vhost.pp 28 KB

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