vhost.pp 27 KB

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