vhost.pp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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_hide_header = $::nginx::config::proxy_hide_header,
  224. $proxy_cache = false,
  225. $proxy_cache_key = undef,
  226. $proxy_cache_use_stale = undef,
  227. $proxy_cache_valid = false,
  228. $proxy_method = undef,
  229. $proxy_set_body = undef,
  230. $resolver = [],
  231. $fastcgi = undef,
  232. $fastcgi_params = "${::nginx::config::conf_dir}/fastcgi_params",
  233. $fastcgi_script = undef,
  234. $uwsgi = undef,
  235. $uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
  236. $index_files = [
  237. 'index.html',
  238. 'index.htm',
  239. 'index.php'],
  240. $autoindex = undef,
  241. $server_name = [$name],
  242. $www_root = undef,
  243. $rewrite_www_to_non_www = false,
  244. $rewrite_to_https = undef,
  245. $location_custom_cfg = undef,
  246. $location_cfg_prepend = undef,
  247. $location_cfg_append = undef,
  248. $location_custom_cfg_prepend = undef,
  249. $location_custom_cfg_append = undef,
  250. $try_files = undef,
  251. $auth_basic = undef,
  252. $auth_basic_user_file = undef,
  253. $client_body_timeout = undef,
  254. $client_header_timeout = undef,
  255. $client_max_body_size = undef,
  256. $raw_prepend = undef,
  257. $raw_append = undef,
  258. $location_raw_prepend = undef,
  259. $location_raw_append = undef,
  260. $vhost_cfg_prepend = undef,
  261. $vhost_cfg_append = undef,
  262. $vhost_cfg_ssl_prepend = undef,
  263. $vhost_cfg_ssl_append = undef,
  264. $include_files = undef,
  265. $access_log = undef,
  266. $error_log = undef,
  267. $format_log = 'combined',
  268. $passenger_cgi_param = undef,
  269. $passenger_set_header = undef,
  270. $passenger_env_var = undef,
  271. $log_by_lua = undef,
  272. $log_by_lua_file = undef,
  273. $use_default_location = true,
  274. $rewrite_rules = [],
  275. $string_mappings = {},
  276. $geo_mappings = {},
  277. $gzip_types = undef,
  278. $owner = $::nginx::config::global_owner,
  279. $group = $::nginx::config::global_group,
  280. $mode = $::nginx::config::global_mode,
  281. $maintenance = false,
  282. $maintenance_value = 'return 503',
  283. $locations = {}
  284. ) {
  285. validate_re($ensure, '^(present|absent)$',
  286. "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
  287. if !(is_array($listen_ip) or is_string($listen_ip)) {
  288. fail('$listen_ip must be a string or array.')
  289. }
  290. if is_string($listen_port) {
  291. warning('DEPRECATION: String $listen_port must be converted to an integer. Integer string support will be removed in a future release.')
  292. }
  293. elsif !is_integer($listen_port) {
  294. fail('$listen_port must be an integer.')
  295. }
  296. if ($listen_options != undef) {
  297. validate_string($listen_options)
  298. }
  299. validate_bool($listen_unix_socket_enable)
  300. if !(is_array($listen_unix_socket) or is_string($listen_unix_socket)) {
  301. fail('$listen_unix_socket must be a string or array.')
  302. }
  303. if ($listen_unix_socket_options != undef) {
  304. validate_string($listen_unix_socket_options)
  305. }
  306. if ($location_satisfy != undef) {
  307. validate_re($location_satisfy, '^(any|all)$',
  308. "${$location_satisfy} is not supported for location_satisfy. Allowed values are 'any' and 'all'.")
  309. }
  310. validate_array($location_allow)
  311. validate_array($location_deny)
  312. validate_bool($ipv6_enable)
  313. if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
  314. fail('$ipv6_listen_ip must be a string or array.')
  315. }
  316. if is_string($ipv6_listen_port) {
  317. warning('DEPRECATION: String $ipv6_listen_port must be converted to an integer. Integer string support will be removed in a future release.')
  318. }
  319. elsif !is_integer($ipv6_listen_port) {
  320. fail('$ipv6_listen_port must be an integer.')
  321. }
  322. validate_string($ipv6_listen_options)
  323. if ($add_header != undef) {
  324. validate_hash($add_header)
  325. }
  326. validate_bool($ssl)
  327. if ($ssl_cert != undef) {
  328. validate_string($ssl_cert)
  329. }
  330. if ($ssl_client_cert != undef) {
  331. validate_string($ssl_client_cert)
  332. }
  333. if ($ssl_verify_client != undef) {
  334. validate_string($ssl_verify_client)
  335. }
  336. if ($ssl_crl != undef) {
  337. validate_string($ssl_crl)
  338. }
  339. validate_bool($ssl_listen_option)
  340. if ($ssl_dhparam != undef) {
  341. validate_string($ssl_dhparam)
  342. }
  343. if ($ssl_key != undef) {
  344. validate_string($ssl_key)
  345. }
  346. if is_string($ssl_port) {
  347. warning('DEPRECATION: String $ssl_port must be converted to an integer. Integer string support will be removed in a future release.')
  348. }
  349. elsif !is_integer($ssl_port) {
  350. fail('$ssl_port must be an integer.')
  351. }
  352. validate_string($ssl_protocols)
  353. validate_string($ssl_ciphers)
  354. validate_string($ssl_cache)
  355. validate_bool($ssl_stapling)
  356. if ($ssl_stapling_file != undef) {
  357. validate_string($ssl_stapling_file)
  358. }
  359. if ($ssl_stapling_responder != undef) {
  360. validate_string($ssl_stapling_responder)
  361. }
  362. validate_bool($ssl_stapling_verify)
  363. validate_string($ssl_session_timeout)
  364. if ($ssl_session_tickets) {
  365. validate_string($ssl_session_tickets)
  366. }
  367. if ($ssl_session_ticket_key) {
  368. validate_string($ssl_session_ticket_key)
  369. }
  370. if ($ssl_trusted_cert != undef) {
  371. validate_string($ssl_trusted_cert)
  372. }
  373. validate_string($spdy)
  374. if ($proxy != undef) {
  375. validate_string($proxy)
  376. }
  377. validate_string($proxy_read_timeout)
  378. if ($proxy_redirect != undef) {
  379. validate_string($proxy_redirect)
  380. }
  381. validate_array($proxy_set_header)
  382. validate_array($proxy_hide_header)
  383. if ($proxy_cache != false) {
  384. validate_string($proxy_cache)
  385. }
  386. if ($proxy_cache_key != undef) {
  387. validate_string($proxy_cache_key)
  388. }
  389. if ($proxy_cache_use_stale != undef) {
  390. validate_string($proxy_cache_use_stale)
  391. }
  392. if ($proxy_cache_valid != false) {
  393. if !(is_array($proxy_cache_valid) or is_string($proxy_cache_valid)) {
  394. fail('$proxy_cache_valid must be a string or an array or false.')
  395. }
  396. }
  397. if ($proxy_method != undef) {
  398. validate_string($proxy_method)
  399. }
  400. if ($proxy_set_body != undef) {
  401. validate_string($proxy_set_body)
  402. }
  403. validate_array($resolver)
  404. if ($fastcgi != undef) {
  405. validate_string($fastcgi)
  406. }
  407. validate_string($fastcgi_params)
  408. if ($fastcgi_script != undef) {
  409. validate_string($fastcgi_script)
  410. }
  411. if ($uwsgi != undef) {
  412. validate_string($uwsgi)
  413. }
  414. validate_string($uwsgi_params)
  415. validate_array($index_files)
  416. if ($autoindex != undef) {
  417. validate_string($autoindex)
  418. }
  419. validate_array($server_name)
  420. if ($www_root != undef) {
  421. validate_string($www_root)
  422. }
  423. validate_bool($rewrite_www_to_non_www)
  424. if ($rewrite_to_https != undef) {
  425. validate_bool($rewrite_to_https)
  426. }
  427. if ($raw_prepend != undef) {
  428. if (is_array($raw_prepend)) {
  429. validate_array($raw_prepend)
  430. } else {
  431. validate_string($raw_prepend)
  432. }
  433. }
  434. if ($raw_append != undef) {
  435. if (is_array($raw_append)) {
  436. validate_array($raw_append)
  437. } else {
  438. validate_string($raw_append)
  439. }
  440. }
  441. if ($location_raw_prepend != undef) {
  442. if (is_array($location_raw_prepend)) {
  443. validate_array($location_raw_prepend)
  444. } else {
  445. validate_string($location_raw_prepend)
  446. }
  447. }
  448. if ($location_raw_append != undef) {
  449. if (is_array($location_raw_append)) {
  450. validate_array($location_raw_append)
  451. } else {
  452. validate_string($location_raw_append)
  453. }
  454. }
  455. if ($location_custom_cfg != undef) {
  456. validate_hash($location_custom_cfg)
  457. }
  458. if ($location_cfg_prepend != undef) {
  459. validate_hash($location_cfg_prepend)
  460. }
  461. if ($location_cfg_append != undef) {
  462. validate_hash($location_cfg_append)
  463. }
  464. if ($try_files != undef) {
  465. validate_array($try_files)
  466. }
  467. if ($auth_basic != undef) {
  468. validate_string($auth_basic)
  469. }
  470. if ($auth_basic_user_file != undef) {
  471. validate_string($auth_basic_user_file)
  472. }
  473. if ($vhost_cfg_prepend != undef) {
  474. validate_hash($vhost_cfg_prepend)
  475. }
  476. if ($vhost_cfg_append != undef) {
  477. validate_hash($vhost_cfg_append)
  478. }
  479. if ($vhost_cfg_ssl_prepend != undef) {
  480. validate_hash($vhost_cfg_ssl_prepend)
  481. }
  482. if ($vhost_cfg_ssl_append != undef) {
  483. validate_hash($vhost_cfg_ssl_append)
  484. }
  485. if ($include_files != undef) {
  486. validate_array($include_files)
  487. }
  488. if ($access_log != undef) {
  489. validate_string($access_log)
  490. }
  491. if ($error_log != undef) {
  492. validate_string($error_log)
  493. }
  494. if ($passenger_cgi_param != undef) {
  495. validate_hash($passenger_cgi_param)
  496. }
  497. if ($passenger_set_header != undef) {
  498. validate_hash($passenger_set_header)
  499. }
  500. if ($passenger_env_var != undef) {
  501. validate_hash($passenger_env_var)
  502. }
  503. if ($log_by_lua != undef) {
  504. validate_string($log_by_lua)
  505. }
  506. if ($log_by_lua_file != undef) {
  507. validate_string($log_by_lua_file)
  508. }
  509. if ($client_body_timeout != undef) {
  510. validate_string($client_body_timeout)
  511. }
  512. if ($client_header_timeout != undef) {
  513. validate_string($client_header_timeout)
  514. }
  515. if ($gzip_types != undef) {
  516. validate_string($gzip_types)
  517. }
  518. validate_bool($use_default_location)
  519. validate_array($rewrite_rules)
  520. validate_hash($string_mappings)
  521. validate_hash($geo_mappings)
  522. validate_hash($locations)
  523. validate_string($owner)
  524. validate_string($group)
  525. validate_re($mode, '^\d{4}$',
  526. "${mode} is not valid. It should be 4 digits (0644 by default).")
  527. # Variables
  528. $vhost_dir = "${::nginx::config::conf_dir}/sites-available"
  529. $vhost_enable_dir = "${::nginx::config::conf_dir}/sites-enabled"
  530. $vhost_symlink_ensure = $ensure ? {
  531. 'absent' => absent,
  532. default => 'link',
  533. }
  534. $name_sanitized = regsubst($name, ' ', '_', 'G')
  535. $config_file = "${vhost_dir}/${name_sanitized}.conf"
  536. File {
  537. ensure => $ensure ? {
  538. 'absent' => absent,
  539. default => 'file',
  540. },
  541. notify => Class['::nginx::service'],
  542. owner => $owner,
  543. group => $group,
  544. mode => $mode,
  545. }
  546. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  547. # and support does not exist for it in the kernel.
  548. if ($ipv6_enable == true) and (!$::ipaddress6) {
  549. warning('nginx: IPv6 support is not enabled or configured properly')
  550. }
  551. # Check to see if SSL Certificates are properly defined.
  552. if ($ssl == true) {
  553. if ($ssl_cert == undef) or ($ssl_key == undef) {
  554. fail('nginx: SSL certificate/key (ssl_cert/ssl_key) and/or SSL Private must be defined and exist on the target system(s)')
  555. }
  556. }
  557. # This was a lot to add up in parameter list so add it down here
  558. # Also opted to add more logic here and keep template cleaner which
  559. # unfortunately means resorting to the $varname_real thing
  560. $access_log_real = $access_log ? {
  561. 'off' => 'off',
  562. undef => "${::nginx::config::log_dir}/${name_sanitized}.access.log ${format_log}",
  563. default => "${access_log} ${format_log}",
  564. }
  565. $error_log_real = $error_log ? {
  566. undef => "${::nginx::config::log_dir}/${name_sanitized}.error.log",
  567. default => $error_log,
  568. }
  569. concat { $config_file:
  570. owner => $owner,
  571. group => $group,
  572. mode => $mode,
  573. notify => Class['::nginx::service'],
  574. }
  575. $ssl_only = ($ssl == true) and (($ssl_port + 0) == ($listen_port + 0))
  576. if $use_default_location == true {
  577. # Create the default location reference for the vHost
  578. nginx::resource::location {"${name_sanitized}-default":
  579. ensure => $ensure,
  580. vhost => $name_sanitized,
  581. ssl => $ssl,
  582. ssl_only => $ssl_only,
  583. location => '/',
  584. location_satisfy => $location_satisfy,
  585. location_allow => $location_allow,
  586. location_deny => $location_deny,
  587. proxy => $proxy,
  588. proxy_redirect => $proxy_redirect,
  589. proxy_read_timeout => $proxy_read_timeout,
  590. proxy_connect_timeout => $proxy_connect_timeout,
  591. proxy_cache => $proxy_cache,
  592. proxy_cache_key => $proxy_cache_key,
  593. proxy_cache_use_stale => $proxy_cache_use_stale,
  594. proxy_cache_valid => $proxy_cache_valid,
  595. proxy_method => $proxy_method,
  596. proxy_set_header => $proxy_set_header,
  597. proxy_hide_header => $proxy_hide_header,
  598. proxy_set_body => $proxy_set_body,
  599. fastcgi => $fastcgi,
  600. fastcgi_params => $fastcgi_params,
  601. fastcgi_script => $fastcgi_script,
  602. uwsgi => $uwsgi,
  603. uwsgi_params => $uwsgi_params,
  604. try_files => $try_files,
  605. www_root => $www_root,
  606. autoindex => $autoindex,
  607. index_files => $index_files,
  608. location_custom_cfg => $location_custom_cfg,
  609. location_cfg_prepend => $location_cfg_prepend,
  610. location_cfg_append => $location_cfg_append,
  611. location_custom_cfg_prepend => $location_custom_cfg_prepend,
  612. location_custom_cfg_append => $location_custom_cfg_append,
  613. rewrite_rules => $rewrite_rules,
  614. raw_prepend => $location_raw_prepend,
  615. raw_append => $location_raw_append,
  616. notify => Class['nginx::service'],
  617. }
  618. $root = undef
  619. } else {
  620. $root = $www_root
  621. }
  622. if $fastcgi != undef and !defined(File[$fastcgi_params]) {
  623. file { $fastcgi_params:
  624. ensure => present,
  625. mode => '0770',
  626. content => template('nginx/vhost/fastcgi_params.erb'),
  627. }
  628. }
  629. if $uwsgi != undef and !defined(File[$uwsgi_params]) {
  630. file { $uwsgi_params:
  631. ensure => present,
  632. mode => '0770',
  633. content => template('nginx/vhost/uwsgi_params.erb'),
  634. }
  635. }
  636. if (($listen_port + 0) != ($ssl_port + 0)) {
  637. concat::fragment { "${name_sanitized}-header":
  638. target => $config_file,
  639. content => template('nginx/vhost/vhost_header.erb'),
  640. order => '001',
  641. }
  642. }
  643. # Create a proper file close stub.
  644. if (($listen_port + 0) != ($ssl_port + 0)) {
  645. concat::fragment { "${name_sanitized}-footer":
  646. target => $config_file,
  647. content => template('nginx/vhost/vhost_footer.erb'),
  648. order => '699',
  649. }
  650. }
  651. # Create SSL File Stubs if SSL is enabled
  652. if ($ssl == true) {
  653. # Access and error logs are named differently in ssl template
  654. # This was a lot to add up in parameter list so add it down here
  655. # Also opted to add more logic here and keep template cleaner which
  656. # unfortunately means resorting to the $varname_real thing
  657. $ssl_access_log_real = $access_log ? {
  658. 'off' => 'off',
  659. undef => "${::nginx::config::log_dir}/ssl-${name_sanitized}.access.log ${format_log}",
  660. default => "${access_log} ${format_log}",
  661. }
  662. $ssl_error_log_real = $error_log ? {
  663. undef => "${::nginx::config::log_dir}/ssl-${name_sanitized}.error.log",
  664. default => $error_log,
  665. }
  666. concat::fragment { "${name_sanitized}-ssl-header":
  667. target => $config_file,
  668. content => template('nginx/vhost/vhost_ssl_header.erb'),
  669. order => '700',
  670. }
  671. concat::fragment { "${name_sanitized}-ssl-footer":
  672. target => $config_file,
  673. content => template('nginx/vhost/vhost_ssl_footer.erb'),
  674. order => '999',
  675. }
  676. }
  677. file{ "${name_sanitized}.conf symlink":
  678. ensure => $vhost_symlink_ensure,
  679. path => "${vhost_enable_dir}/${name_sanitized}.conf",
  680. target => $config_file,
  681. require => Concat[$config_file],
  682. notify => Class['::nginx::service'],
  683. }
  684. create_resources('::nginx::resource::map', $string_mappings)
  685. create_resources('::nginx::resource::geo', $geo_mappings)
  686. create_resources('::nginx::resource::location', $locations, {
  687. ensure => $ensure,
  688. vhost => $name_sanitized,
  689. ssl => $ssl,
  690. ssl_only => $ssl_only,
  691. www_root => $www_root,
  692. })
  693. }