vhost.pp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. # define: nginx::resource::vhost
  2. #
  3. # This definition creates a virtual host
  4. #
  5. # Parameters:
  6. # [*ensure*] - Enables or disables the specified vhost
  7. # (present|absent)
  8. # [*listen_ip*] - Default IP Address for NGINX to listen with this
  9. # vHost on. Defaults to all interfaces (*)
  10. # [*listen_port*] - Default IP Port for NGINX to listen with this
  11. # vHost on. Defaults to TCP 80
  12. # [*listen_options*] - Extra options for listen directive like
  13. # 'default' to catchall. Undef by default.
  14. # [*location_allow*] - Array: Locations to allow connections from.
  15. # [*location_deny*] - Array: Locations to deny connections from.
  16. # [*ipv6_enable*] - BOOL value to enable/disable IPv6 support
  17. # (false|true). Module will check to see if IPv6 support exists on your
  18. # system before enabling.
  19. # [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with
  20. # this vHost on. Defaults to all interfaces (::)
  21. # [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this
  22. # vHost on. Defaults to TCP 80
  23. # [*ipv6_listen_options*] - Extra options for listen directive like 'default'
  24. # to catchall. Template will allways add ipv6only=on. While issue
  25. # jfryman/puppet-nginx#30 is discussed, default value is 'default'.
  26. # [*add_header*] - Hash: Adds headers to the HTTP response when
  27. # response code is equal to 200, 204, 301, 302 or 304.
  28. # [*index_files*] - Default index files for NGINX to read when
  29. # traversing a directory
  30. # [*autoindex*] - Set it on 'on' or 'off 'to activate/deactivate
  31. # autoindex directory listing. Undef by default.
  32. # [*proxy*] - Proxy server(s) for the root location to connect
  33. # to. Accepts a single value, can be used in conjunction with
  34. # nginx::resource::upstream
  35. # [*proxy_read_timeout*] - Override the default the proxy read timeout value
  36. # of 90 seconds
  37. # [*proxy_redirect*] - Override the default proxy_redirect value of off.
  38. # [*resolver*] - Array: Configures name servers used to resolve
  39. # names of upstream servers into addresses.
  40. # [*fastcgi*] - location of fastcgi (host:port)
  41. # [*fastcgi_params*] - optional alternative fastcgi_params file to use
  42. # [*fastcgi_script*] - optional SCRIPT_FILE parameter
  43. # [*ssl*] - Indicates whether to setup SSL bindings for this
  44. # vhost.
  45. # [*ssl_cert*] - Pre-generated SSL Certificate file to reference
  46. # for SSL Support. This is not generated by this module.
  47. # [*ssl_dhparam*] - This directive specifies a file containing
  48. # Diffie-Hellman key agreement protocol cryptographic parameters, in PEM
  49. # format, utilized for exchanging session keys between server and client.
  50. # [*ssl_key*] - Pre-generated SSL Key file to reference for SSL
  51. # Support. This is not generated by this module.
  52. # [*ssl_port*] - Default IP Port for NGINX to listen with this SSL
  53. # vHost on. Defaults to TCP 443
  54. # [*ssl_protocols*] - SSL protocols enabled. Defaults to 'SSLv3 TLSv1
  55. # TLSv1.1 TLSv1.2'.
  56. # [*ssl_ciphers*] - SSL ciphers enabled. Defaults to
  57. # 'HIGH:!aNULL:!MD5'.
  58. # [*ssl_stapling*] - Bool: Enables or disables stapling of OCSP
  59. # responses by the server. Defaults to false.
  60. # [*ssl_stapling_file*] - String: When set, the stapled OCSP response
  61. # will be taken from the specified file instead of querying the OCSP
  62. # responder specified in the server certificate.
  63. # [*ssl_stapling_responder*] - String: Overrides the URL of the OCSP
  64. # responder specified in the Authority Information Access certificate
  65. # extension.
  66. # [*ssl_stapling_verify*] - Bool: Enables or disables verification of
  67. # OCSP responses by the server. Defaults to false.
  68. # [*ssl_trusted_cert*] - String: Specifies a file with trusted CA
  69. # certificates in the PEM format used to verify client certificates and
  70. # OCSP responses if ssl_stapling is enabled.
  71. # [*spdy*] - Toggles SPDY protocol.
  72. # [*server_name*] - List of vhostnames for which this vhost will
  73. # respond. Default [$name].
  74. # [*www_root*] - Specifies the location on disk for files to be
  75. # read from. Cannot be set in conjunction with $proxy
  76. # [*rewrite_www_to_non_www*] - Adds a server directive and rewrite rule to
  77. # rewrite www.domain.com to domain.com in order to avoid duplicate
  78. # content (SEO);
  79. # [*try_files*] - Specifies the locations for files to be
  80. # checked as an array. Cannot be used in conjuction with $proxy.
  81. # [*proxy_cache*] - This directive sets name of zone for caching.
  82. # The same zone can be used in multiple places.
  83. # [*proxy_cache_valid*] - This directive sets the time for caching
  84. # different replies.
  85. # [*proxy_method*] - If defined, overrides the HTTP method of the
  86. # request to be passed to the backend.
  87. # [*proxy_set_body*] - If defined, sets the body passed to the backend.
  88. # [*auth_basic*] - This directive includes testing name and
  89. # password with HTTP Basic Authentication.
  90. # [*auth_basic_user_file*] - This directive sets the htpasswd filename for
  91. # the authentication realm.
  92. # [*client_max_body_size*] - This directive sets client_max_body_size.
  93. # [*client_body_timeout*] - Sets how long the server will wait for a
  94. # client body. Default is 60s
  95. # [*client_header_timeout*] - Sets how long the server will wait for a
  96. # client header. Default is 60s
  97. # [*raw_prepend*] - A single string, or an array of strings to
  98. # prepend to the server directive (after cfg prepend directives). NOTE:
  99. # YOU are responsible for a semicolon on each line that requires one.
  100. # [*raw_append*] - A single string, or an array of strings to
  101. # append to the server directive (after cfg append directives). NOTE:
  102. # YOU are responsible for a semicolon on each line that requires one.
  103. # [*location_raw_prepend*] - A single string, or an array of strings
  104. # to prepend to the location directive (after custom_cfg directives). NOTE:
  105. # YOU are responsible for a semicolon on each line that requires one.
  106. # [*location_raw_append*] - A single string, or an array of strings
  107. # to append to the location directive (after custom_cfg directives). NOTE:
  108. # YOU are responsible for a semicolon on each line that requires one.
  109. # [*vhost_cfg_append*] - It expects a hash with custom directives to
  110. # put after everything else inside vhost
  111. # [*vhost_cfg_prepend*] - It expects a hash with custom directives to
  112. # put before everything else inside vhost
  113. # [*vhost_cfg_ssl_append*] - It expects a hash with custom directives to
  114. # put after everything else inside vhost ssl
  115. # [*vhost_cfg_ssl_prepend*] - It expects a hash with custom directives to
  116. # put before everything else inside vhost ssl
  117. # [*rewrite_to_https*] - Adds a server directive and rewrite rule to
  118. # rewrite to ssl
  119. # [*include_files*] - Adds include files to vhost
  120. # [*access_log*] - Where to write access log. May add additional
  121. # options like log format to the end.
  122. # [*error_log*] - Where to write error log. May add additional
  123. # options like error level to the end.
  124. # [*passenger_cgi_param*] - Allows one to define additional CGI environment
  125. # variables to pass to the backend application
  126. # [*log_by_lua*] - Run the Lua source code inlined as the
  127. # <lua-script-str> at the log request processing phase.
  128. # This does not replace the current access logs, but runs after.
  129. # [*log_by_lua_file*] - Equivalent to log_by_lua, except that the file
  130. # specified by <path-to-lua-script-file> contains the Lua code, or, as from
  131. # the v0.5.0rc32 release, the Lua/LuaJIT bytecode to be executed.
  132. # [*gzip_types*] - Defines gzip_types, nginx default is text/html
  133. # [*owner*] - Defines owner of the .conf file
  134. # [*group*] - Defines group of the .conf file
  135. # [*mode*] - Defines mode of the .conf file
  136. # Actions:
  137. #
  138. # Requires:
  139. #
  140. # Sample Usage:
  141. # nginx::resource::vhost { 'test2.local':
  142. # ensure => present,
  143. # www_root => '/var/www/nginx-default',
  144. # ssl => true,
  145. # ssl_cert => '/tmp/server.crt',
  146. # ssl_key => '/tmp/server.pem',
  147. # }
  148. define nginx::resource::vhost (
  149. $ensure = 'present',
  150. $listen_ip = '*',
  151. $listen_port = '80',
  152. $listen_options = undef,
  153. $location_allow = [],
  154. $location_deny = [],
  155. $ipv6_enable = false,
  156. $ipv6_listen_ip = '::',
  157. $ipv6_listen_port = '80',
  158. $ipv6_listen_options = 'default ipv6only=on',
  159. $add_header = undef,
  160. $ssl = false,
  161. $ssl_listen_option = true,
  162. $ssl_cert = undef,
  163. $ssl_dhparam = undef,
  164. $ssl_key = undef,
  165. $ssl_port = '443',
  166. $ssl_protocols = 'SSLv3 TLSv1 TLSv1.1 TLSv1.2',
  167. $ssl_ciphers = 'HIGH:!aNULL:!MD5',
  168. $ssl_cache = 'shared:SSL:10m',
  169. $ssl_stapling = false,
  170. $ssl_stapling_file = undef,
  171. $ssl_stapling_responder = undef,
  172. $ssl_stapling_verify = false,
  173. $ssl_trusted_cert = undef,
  174. $spdy = $nginx::config::spdy,
  175. $proxy = undef,
  176. $proxy_redirect = undef,
  177. $proxy_read_timeout = $nginx::config::proxy_read_timeout,
  178. $proxy_connect_timeout = $nginx::config::proxy_connect_timeout,
  179. $proxy_set_header = [],
  180. $proxy_cache = false,
  181. $proxy_cache_valid = false,
  182. $proxy_method = undef,
  183. $proxy_set_body = undef,
  184. $resolver = [],
  185. $fastcgi = undef,
  186. $fastcgi_params = "${nginx::config::conf_dir}/fastcgi_params",
  187. $fastcgi_script = undef,
  188. $index_files = [
  189. 'index.html',
  190. 'index.htm',
  191. 'index.php'],
  192. $autoindex = undef,
  193. $server_name = [$name],
  194. $www_root = undef,
  195. $rewrite_www_to_non_www = false,
  196. $rewrite_to_https = undef,
  197. $location_custom_cfg = undef,
  198. $location_cfg_prepend = undef,
  199. $location_cfg_append = undef,
  200. $location_custom_cfg_prepend = undef,
  201. $location_custom_cfg_append = undef,
  202. $try_files = undef,
  203. $auth_basic = undef,
  204. $auth_basic_user_file = undef,
  205. $client_body_timeout = undef,
  206. $client_header_timeout = undef,
  207. $client_max_body_size = undef,
  208. $raw_prepend = undef,
  209. $raw_append = undef,
  210. $location_raw_prepend = undef,
  211. $location_raw_append = undef,
  212. $vhost_cfg_prepend = undef,
  213. $vhost_cfg_append = undef,
  214. $vhost_cfg_ssl_prepend = undef,
  215. $vhost_cfg_ssl_append = undef,
  216. $include_files = undef,
  217. $access_log = undef,
  218. $error_log = undef,
  219. $format_log = undef,
  220. $passenger_cgi_param = undef,
  221. $log_by_lua = undef,
  222. $log_by_lua_file = undef,
  223. $use_default_location = true,
  224. $rewrite_rules = [],
  225. $string_mappings = {},
  226. $geo_mappings = {},
  227. $gzip_types = undef,
  228. $owner = $nginx::config::global_owner,
  229. $group = $nginx::config::global_group,
  230. $mode = $nginx::config::global_mode,
  231. ) {
  232. validate_re($ensure, '^(present|absent)$',
  233. "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
  234. validate_string($listen_ip)
  235. if !is_integer($listen_port) {
  236. fail('$listen_port must be an integer.')
  237. }
  238. if ($listen_options != undef) {
  239. validate_string($listen_options)
  240. }
  241. validate_array($location_allow)
  242. validate_array($location_deny)
  243. validate_bool($ipv6_enable)
  244. validate_string($ipv6_listen_ip)
  245. if !is_integer($ipv6_listen_port) {
  246. fail('$ipv6_listen_port must be an integer.')
  247. }
  248. validate_string($ipv6_listen_options)
  249. if ($add_header != undef) {
  250. validate_hash($add_header)
  251. }
  252. validate_bool($ssl)
  253. if ($ssl_cert != undef) {
  254. validate_string($ssl_cert)
  255. }
  256. validate_bool($ssl_listen_option)
  257. if ($ssl_dhparam != undef) {
  258. validate_string($ssl_dhparam)
  259. }
  260. if ($ssl_key != undef) {
  261. validate_string($ssl_key)
  262. }
  263. if !is_integer($ssl_port) {
  264. fail('$ssl_port must be an integer.')
  265. }
  266. validate_string($ssl_protocols)
  267. validate_string($ssl_ciphers)
  268. validate_string($ssl_cache)
  269. validate_bool($ssl_stapling)
  270. if ($ssl_stapling_file != undef) {
  271. validate_string($ssl_stapling_file)
  272. }
  273. if ($ssl_stapling_responder != undef) {
  274. validate_string($ssl_stapling_responder)
  275. }
  276. validate_bool($ssl_stapling_verify)
  277. if ($ssl_trusted_cert != undef) {
  278. validate_string($ssl_trusted_cert)
  279. }
  280. validate_string($spdy)
  281. if ($proxy != undef) {
  282. validate_string($proxy)
  283. }
  284. validate_string($proxy_read_timeout)
  285. validate_string($proxy_redirect)
  286. validate_array($proxy_set_header)
  287. if ($proxy_cache != false) {
  288. validate_string($proxy_cache)
  289. }
  290. if ($proxy_cache_valid != false) {
  291. validate_string($proxy_cache_valid)
  292. }
  293. if ($proxy_method != undef) {
  294. validate_string($proxy_method)
  295. }
  296. if ($proxy_set_body != undef) {
  297. validate_string($proxy_set_body)
  298. }
  299. validate_array($resolver)
  300. if ($fastcgi != undef) {
  301. validate_string($fastcgi)
  302. }
  303. validate_string($fastcgi_params)
  304. if ($fastcgi_script != undef) {
  305. validate_string($fastcgi_script)
  306. }
  307. validate_array($index_files)
  308. if ($autoindex != undef) {
  309. validate_string($autoindex)
  310. }
  311. validate_array($server_name)
  312. if ($www_root != undef) {
  313. validate_string($www_root)
  314. }
  315. validate_bool($rewrite_www_to_non_www)
  316. if ($rewrite_to_https != undef) {
  317. validate_bool($rewrite_to_https)
  318. }
  319. if ($raw_prepend != undef) {
  320. if (is_array($raw_prepend)) {
  321. validate_array($raw_prepend)
  322. } else {
  323. validate_string($raw_prepend)
  324. }
  325. }
  326. if ($raw_append != undef) {
  327. if (is_array($raw_append)) {
  328. validate_array($raw_append)
  329. } else {
  330. validate_string($raw_append)
  331. }
  332. }
  333. if ($location_raw_prepend != undef) {
  334. if (is_array($location_raw_prepend)) {
  335. validate_array($location_raw_prepend)
  336. } else {
  337. validate_string($location_raw_prepend)
  338. }
  339. }
  340. if ($location_raw_append != undef) {
  341. if (is_array($location_raw_append)) {
  342. validate_array($location_raw_append)
  343. } else {
  344. validate_string($location_raw_append)
  345. }
  346. }
  347. if ($location_custom_cfg != undef) {
  348. validate_hash($location_custom_cfg)
  349. }
  350. if ($location_cfg_prepend != undef) {
  351. validate_hash($location_cfg_prepend)
  352. }
  353. if ($location_cfg_append != undef) {
  354. validate_hash($location_cfg_append)
  355. }
  356. if ($try_files != undef) {
  357. validate_array($try_files)
  358. }
  359. if ($auth_basic != undef) {
  360. validate_string($auth_basic)
  361. }
  362. if ($auth_basic_user_file != undef) {
  363. validate_string($auth_basic_user_file)
  364. }
  365. if ($vhost_cfg_prepend != undef) {
  366. validate_hash($vhost_cfg_prepend)
  367. }
  368. if ($vhost_cfg_append != undef) {
  369. validate_hash($vhost_cfg_append)
  370. }
  371. if ($vhost_cfg_ssl_prepend != undef) {
  372. validate_hash($vhost_cfg_ssl_prepend)
  373. }
  374. if ($vhost_cfg_ssl_append != undef) {
  375. validate_hash($vhost_cfg_ssl_append)
  376. }
  377. if ($include_files != undef) {
  378. validate_array($include_files)
  379. }
  380. if ($access_log != undef) {
  381. validate_string($access_log)
  382. }
  383. if ($error_log != undef) {
  384. validate_string($error_log)
  385. }
  386. if ($passenger_cgi_param != undef) {
  387. validate_hash($passenger_cgi_param)
  388. }
  389. if ($log_by_lua != undef) {
  390. validate_string($log_by_lua)
  391. }
  392. if ($log_by_lua_file != undef) {
  393. validate_string($log_by_lua_file)
  394. }
  395. if ($client_body_timeout != undef) {
  396. validate_string($client_body_timeout)
  397. }
  398. if ($client_header_timeout != undef) {
  399. validate_string($client_header_timeout)
  400. }
  401. if ($gzip_types != undef) {
  402. validate_string($gzip_types)
  403. }
  404. validate_bool($use_default_location)
  405. validate_array($rewrite_rules)
  406. validate_hash($string_mappings)
  407. validate_hash($geo_mappings)
  408. validate_string($owner)
  409. validate_string($group)
  410. validate_re($mode, '^\d{4}$',
  411. "${mode} is not valid. It should be 4 digits (0644 by default).")
  412. # Variables
  413. $vhost_dir = "${nginx::config::conf_dir}/sites-available"
  414. $vhost_enable_dir = "${nginx::config::conf_dir}/sites-enabled"
  415. $vhost_symlink_ensure = $ensure ? {
  416. 'absent' => absent,
  417. default => 'link',
  418. }
  419. $name_sanitized = regsubst($name, ' ', '_', 'G')
  420. $config_file = "${vhost_dir}/${name_sanitized}.conf"
  421. File {
  422. ensure => $ensure ? {
  423. 'absent' => absent,
  424. default => 'file',
  425. },
  426. notify => Class['nginx::service'],
  427. owner => $owner,
  428. group => $group,
  429. mode => $mode,
  430. }
  431. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  432. # and support does not exist for it in the kernel.
  433. if ($ipv6_enable == true) and (!$::ipaddress6) {
  434. warning('nginx: IPv6 support is not enabled or configured properly')
  435. }
  436. # Check to see if SSL Certificates are properly defined.
  437. if ($ssl == true) {
  438. if ($ssl_cert == undef) or ($ssl_key == undef) {
  439. fail('nginx: SSL certificate/key (ssl_cert/ssl_key) and/or SSL Private must be defined and exist on the target system(s)')
  440. }
  441. }
  442. # This was a lot to add up in parameter list so add it down here
  443. # Also opted to add more logic here and keep template cleaner which
  444. # unfortunately means resorting to the $varname_real thing
  445. $access_log_tmp = $access_log ? {
  446. undef => "${nginx::config::logdir}/${name_sanitized}.access.log",
  447. default => $access_log,
  448. }
  449. $access_log_real = $format_log ? {
  450. undef => $access_log_tmp,
  451. default => "${access_log_tmp} ${format_log}",
  452. }
  453. $error_log_real = $error_log ? {
  454. undef => "${nginx::config::logdir}/${name_sanitized}.error.log",
  455. default => $error_log,
  456. }
  457. concat { $config_file:
  458. owner => $owner,
  459. group => $group,
  460. mode => $mode,
  461. notify => Class['nginx::service'],
  462. }
  463. $ssl_only = ($ssl == true) and ($ssl_port == $listen_port)
  464. if $use_default_location == true {
  465. # Create the default location reference for the vHost
  466. nginx::resource::location {"${name_sanitized}-default":
  467. ensure => $ensure,
  468. vhost => $name_sanitized,
  469. ssl => $ssl,
  470. ssl_only => $ssl_only,
  471. location => '/',
  472. location_allow => $location_allow,
  473. location_deny => $location_deny,
  474. proxy => $proxy,
  475. proxy_redirect => $proxy_redirect,
  476. proxy_read_timeout => $proxy_read_timeout,
  477. proxy_connect_timeout => $proxy_connect_timeout,
  478. proxy_cache => $proxy_cache,
  479. proxy_cache_valid => $proxy_cache_valid,
  480. proxy_method => $proxy_method,
  481. proxy_set_body => $proxy_set_body,
  482. fastcgi => $fastcgi,
  483. fastcgi_params => $fastcgi_params,
  484. fastcgi_script => $fastcgi_script,
  485. try_files => $try_files,
  486. www_root => $www_root,
  487. autoindex => $autoindex,
  488. index_files => [],
  489. location_custom_cfg => $location_custom_cfg,
  490. notify => Class['nginx::service'],
  491. rewrite_rules => $rewrite_rules,
  492. raw_prepend => $location_raw_prepend,
  493. raw_append => $location_raw_append
  494. }
  495. $root = undef
  496. } else {
  497. $root = $www_root
  498. }
  499. # Support location_cfg_prepend and location_cfg_append on default location created by vhost
  500. if $location_cfg_prepend {
  501. Nginx::Resource::Location["${name_sanitized}-default"] {
  502. location_cfg_prepend => $location_cfg_prepend }
  503. }
  504. if $location_cfg_append {
  505. Nginx::Resource::Location["${name_sanitized}-default"] {
  506. location_cfg_append => $location_cfg_append }
  507. }
  508. if $location_custom_cfg_prepend {
  509. Nginx::Resource::Location["${name_sanitized}-default"] {
  510. location_custom_cfg_prepend => $location_custom_cfg_prepend }
  511. }
  512. if $location_custom_cfg_append {
  513. Nginx::Resource::Location["${name_sanitized}-default"] {
  514. location_custom_cfg_append => $location_custom_cfg_append }
  515. }
  516. if $fastcgi != undef and !defined(File[$fastcgi_params]) {
  517. file { $fastcgi_params:
  518. ensure => present,
  519. mode => '0770',
  520. content => template('nginx/vhost/fastcgi_params.erb'),
  521. }
  522. }
  523. if ($listen_port != $ssl_port) {
  524. concat::fragment { "${name_sanitized}-header":
  525. ensure => present,
  526. target => $config_file,
  527. content => template('nginx/vhost/vhost_header.erb'),
  528. order => '001',
  529. }
  530. }
  531. # Create a proper file close stub.
  532. if ($listen_port != $ssl_port) {
  533. concat::fragment { "${name_sanitized}-footer":
  534. ensure => present,
  535. target => $config_file,
  536. content => template('nginx/vhost/vhost_footer.erb'),
  537. order => '699',
  538. }
  539. }
  540. # Create SSL File Stubs if SSL is enabled
  541. if ($ssl == true) {
  542. # Access and error logs are named differently in ssl template
  543. # This was a lot to add up in parameter list so add it down here
  544. # Also opted to add more logic here and keep template cleaner which
  545. # unfortunately means resorting to the $varname_real thing
  546. $ssl_access_log_tmp = $access_log ? {
  547. undef => "${nginx::config::logdir}/ssl-${name_sanitized}.access.log",
  548. default => $access_log,
  549. }
  550. $ssl_access_log_real = $format_log ? {
  551. undef => $ssl_access_log_tmp,
  552. default => "${ssl_access_log_tmp} ${format_log}",
  553. }
  554. $ssl_error_log_real = $error_log ? {
  555. undef => "${nginx::config::logdir}/ssl-${name_sanitized}.error.log",
  556. default => $error_log,
  557. }
  558. concat::fragment { "${name_sanitized}-ssl-header":
  559. target => $config_file,
  560. content => template('nginx/vhost/vhost_ssl_header.erb'),
  561. order => '700',
  562. }
  563. concat::fragment { "${name_sanitized}-ssl-footer":
  564. target => $config_file,
  565. content => template('nginx/vhost/vhost_ssl_footer.erb'),
  566. order => '999',
  567. }
  568. #Generate ssl key/cert with provided file-locations
  569. $cert = regsubst($name,' ','_', 'G')
  570. # Check if the file has been defined before creating the file to
  571. # avoid the error when using wildcard cert on the multiple vhosts
  572. ensure_resource('file', "${nginx::config::conf_dir}/${cert}.crt", {
  573. owner => $nginx::config::daemon_user,
  574. mode => '0444',
  575. source => $ssl_cert,
  576. })
  577. ensure_resource('file', "${nginx::config::conf_dir}/${cert}.key", {
  578. owner => $nginx::config::daemon_user,
  579. mode => '0440',
  580. source => $ssl_key,
  581. })
  582. if ($ssl_dhparam != undef) {
  583. ensure_resource('file', "${nginx::config::conf_dir}/${cert}.dh.pem", {
  584. owner => $nginx::config::daemon_user,
  585. mode => '0440',
  586. source => $ssl_dhparam,
  587. })
  588. }
  589. if ($ssl_stapling_file != undef) {
  590. ensure_resource('file', "${nginx::config::conf_dir}/${cert}.ocsp.resp", {
  591. owner => $nginx::config::daemon_user,
  592. mode => '0440',
  593. source => $ssl_stapling_file,
  594. })
  595. }
  596. if ($ssl_trusted_cert != undef) {
  597. ensure_resource('file', "${nginx::config::conf_dir}/${cert}.trusted.crt", {
  598. owner => $nginx::config::daemon_user,
  599. mode => '0440',
  600. source => $ssl_trusted_cert,
  601. })
  602. }
  603. }
  604. file{ "${name_sanitized}.conf symlink":
  605. ensure => $vhost_symlink_ensure,
  606. path => "${vhost_enable_dir}/${name_sanitized}.conf",
  607. target => $config_file,
  608. require => Concat[$config_file],
  609. notify => Service['nginx'],
  610. }
  611. create_resources('nginx::resource::map', $string_mappings)
  612. create_resources('nginx::resource::geo', $geo_mappings)
  613. }