vhost.pp 30 KB

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