config.pp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. # Class: nginx::config
  2. #
  3. # This module manages NGINX bootstrap and configuration
  4. #
  5. # Parameters:
  6. #
  7. # There are no default parameters for this class.
  8. #
  9. # Actions:
  10. #
  11. # Requires:
  12. #
  13. # Sample Usage:
  14. #
  15. # This class file is not called directly
  16. class nginx::config(
  17. ### START Module/App Configuration ###
  18. $client_body_temp_path = $::nginx::params::client_body_temp_path,
  19. $confd_purge = false,
  20. $conf_dir = $::nginx::params::conf_dir,
  21. $daemon_user = $::nginx::params::daemon_user,
  22. $global_owner = $::nginx::params::global_owner,
  23. $global_group = $::nginx::params::global_group,
  24. $global_mode = $::nginx::params::global_mode,
  25. $log_dir = $::nginx::params::log_dir,
  26. $http_access_log = $::nginx::params::http_access_log,
  27. $nginx_error_log = $::nginx::params::nginx_error_log,
  28. $nginx_error_log_severity = 'error',
  29. $pid = $::nginx::params::pid,
  30. $proxy_temp_path = $::nginx::params::proxy_temp_path,
  31. $root_group = $::nginx::params::root_group,
  32. $run_dir = $::nginx::params::run_dir,
  33. $sites_available_owner = $::nginx::params::sites_available_owner,
  34. $sites_available_group = $::nginx::params::sites_available_group,
  35. $sites_available_mode = $::nginx::params::sites_available_mode,
  36. $super_user = $::nginx::params::super_user,
  37. $temp_dir = $::nginx::params::temp_dir,
  38. $vhost_purge = false,
  39. # Primary Templates
  40. $conf_template = 'nginx/conf.d/nginx.conf.erb',
  41. $proxy_conf_template = undef,
  42. ### END Module/App Configuration ###
  43. ### START Nginx Configuration ###
  44. $accept_mutex = 'on',
  45. $accept_mutex_delay = '500ms',
  46. $client_body_buffer_size = '128k',
  47. $client_max_body_size = '10m',
  48. $events_use = false,
  49. $fastcgi_cache_inactive = '20m',
  50. $fastcgi_cache_key = false,
  51. $fastcgi_cache_keys_zone = 'd3:100m',
  52. $fastcgi_cache_levels = '1',
  53. $fastcgi_cache_max_size = '500m',
  54. $fastcgi_cache_path = false,
  55. $fastcgi_cache_use_stale = false,
  56. $gzip = 'on',
  57. $gzip_buffers = undef,
  58. $gzip_comp_level = 1,
  59. $gzip_disable = 'msie6',
  60. $gzip_min_length = 20,
  61. $gzip_http_version = 1.1,
  62. $gzip_proxied = 'off',
  63. $gzip_types = undef,
  64. $gzip_vary = 'off',
  65. $http_cfg_append = false,
  66. $http_tcp_nodelay = 'on',
  67. $http_tcp_nopush = 'off',
  68. $keepalive_timeout = '65',
  69. $log_format = {},
  70. $mail = false,
  71. $stream = false,
  72. $multi_accept = 'off',
  73. $names_hash_bucket_size = '64',
  74. $names_hash_max_size = '512',
  75. $nginx_cfg_prepend = false,
  76. $proxy_buffers = '32 4k',
  77. $proxy_buffer_size = '8k',
  78. $proxy_cache_inactive = '20m',
  79. $proxy_cache_keys_zone = 'd2:100m',
  80. $proxy_cache_levels = '1',
  81. $proxy_cache_max_size = '500m',
  82. $proxy_cache_path = false,
  83. $proxy_connect_timeout = '90',
  84. $proxy_headers_hash_bucket_size = '64',
  85. $proxy_http_version = undef,
  86. $proxy_read_timeout = '90',
  87. $proxy_redirect = 'off',
  88. $proxy_send_timeout = '90',
  89. $proxy_set_header = [
  90. 'Host $host',
  91. 'X-Real-IP $remote_addr',
  92. 'X-Forwarded-For $proxy_add_x_forwarded_for',
  93. ],
  94. $proxy_hide_header = [],
  95. $sendfile = 'on',
  96. $server_tokens = 'on',
  97. $spdy = 'off',
  98. $http2 = 'off',
  99. $ssl_stapling = 'off',
  100. $types_hash_bucket_size = '512',
  101. $types_hash_max_size = '1024',
  102. $worker_connections = '1024',
  103. $worker_processes = '1',
  104. $worker_rlimit_nofile = '1024',
  105. ### END Nginx Configuration ###
  106. ) inherits ::nginx::params {
  107. ### Validations ###
  108. if ($worker_processes != 'auto') and (!is_integer($worker_processes)) {
  109. fail('$worker_processes must be an integer or have value "auto".')
  110. }
  111. if (!is_integer($worker_connections)) {
  112. fail('$worker_connections must be an integer.')
  113. }
  114. if (!is_integer($worker_rlimit_nofile)) {
  115. fail('$worker_rlimit_nofile must be an integer.')
  116. }
  117. if (!is_string($events_use)) and ($events_use != false) {
  118. fail('$events_use must be a string or false.')
  119. }
  120. validate_string($multi_accept)
  121. validate_array($proxy_set_header)
  122. validate_array($proxy_hide_header)
  123. if ($proxy_http_version != undef) {
  124. validate_string($proxy_http_version)
  125. }
  126. if ($proxy_conf_template != undef) {
  127. warning('The $proxy_conf_template parameter is deprecated and has no effect.')
  128. }
  129. validate_bool($confd_purge)
  130. validate_bool($vhost_purge)
  131. if ( $proxy_cache_path != false) {
  132. if ( is_string($proxy_cache_path) or is_hash($proxy_cache_path)) {}
  133. else {
  134. fail('proxy_cache_path must be a string or a hash')
  135. }
  136. }
  137. validate_re($proxy_cache_levels, '^[12](:[12])*$')
  138. validate_string($proxy_cache_keys_zone)
  139. validate_string($proxy_cache_max_size)
  140. validate_string($proxy_cache_inactive)
  141. if ($fastcgi_cache_path != false) {
  142. validate_string($fastcgi_cache_path)
  143. }
  144. validate_re($fastcgi_cache_levels, '^[12](:[12])*$')
  145. validate_string($fastcgi_cache_keys_zone)
  146. validate_string($fastcgi_cache_max_size)
  147. validate_string($fastcgi_cache_inactive)
  148. if ($fastcgi_cache_key != false) {
  149. validate_string($fastcgi_cache_key)
  150. }
  151. if ($fastcgi_cache_use_stale != false) {
  152. validate_string($fastcgi_cache_use_stale)
  153. }
  154. validate_bool($mail)
  155. validate_string($server_tokens)
  156. validate_string($client_max_body_size)
  157. if (!is_integer($names_hash_bucket_size)) {
  158. fail('$names_hash_bucket_size must be an integer.')
  159. }
  160. if (!is_integer($names_hash_max_size)) {
  161. fail('$names_hash_max_size must be an integer.')
  162. }
  163. validate_string($proxy_buffers)
  164. validate_string($proxy_buffer_size)
  165. if ($http_cfg_append != false) {
  166. if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
  167. fail('$http_cfg_append must be either a hash or array')
  168. }
  169. }
  170. if ($nginx_cfg_prepend != false) {
  171. if !(is_hash($nginx_cfg_prepend) or is_array($nginx_cfg_prepend)) {
  172. fail('$nginx_cfg_prepend must be either a hash or array')
  173. }
  174. }
  175. validate_string($nginx_error_log)
  176. validate_re($nginx_error_log_severity,['debug','info','notice','warn','error','crit','alert','emerg'],'$nginx_error_log_severity must be debug, info, notice, warn, error, crit, alert or emerg')
  177. validate_string($http_access_log)
  178. validate_string($proxy_headers_hash_bucket_size)
  179. validate_bool($super_user)
  180. ### END VALIDATIONS ###
  181. ### CONFIGURATION ###
  182. File {
  183. owner => $global_owner,
  184. group => $global_group,
  185. mode => $global_mode,
  186. }
  187. file { $conf_dir:
  188. ensure => directory,
  189. }
  190. file { "${conf_dir}/conf.stream.d":
  191. ensure => directory,
  192. }
  193. if $confd_purge == true {
  194. File["${conf_dir}/conf.stream.d"] {
  195. purge => true,
  196. recurse => true,
  197. }
  198. }
  199. file { "${conf_dir}/conf.d":
  200. ensure => directory,
  201. }
  202. if $confd_purge == true {
  203. File["${conf_dir}/conf.d"] {
  204. purge => true,
  205. recurse => true,
  206. notify => Class['::nginx::service'],
  207. }
  208. }
  209. file { "${conf_dir}/conf.mail.d":
  210. ensure => directory,
  211. }
  212. if $confd_purge == true {
  213. File["${conf_dir}/conf.mail.d"] {
  214. purge => true,
  215. recurse => true,
  216. }
  217. }
  218. file { "${conf_dir}/conf.d/vhost_autogen.conf":
  219. ensure => absent,
  220. }
  221. file { "${conf_dir}/conf.mail.d/vhost_autogen.conf":
  222. ensure => absent,
  223. }
  224. file {$run_dir:
  225. ensure => directory,
  226. }
  227. file { $log_dir:
  228. ensure => directory,
  229. }
  230. file {$client_body_temp_path:
  231. ensure => directory,
  232. owner => $daemon_user,
  233. }
  234. file {$proxy_temp_path:
  235. ensure => directory,
  236. owner => $daemon_user,
  237. }
  238. file { "${conf_dir}/sites-available":
  239. ensure => directory,
  240. owner => $sites_available_owner,
  241. group => $sites_available_group,
  242. mode => $sites_available_mode,
  243. }
  244. if $vhost_purge == true {
  245. File["${conf_dir}/sites-available"] {
  246. purge => true,
  247. recurse => true,
  248. }
  249. }
  250. file { "${conf_dir}/sites-enabled":
  251. ensure => directory,
  252. }
  253. if $vhost_purge == true {
  254. File["${conf_dir}/sites-enabled"] {
  255. purge => true,
  256. recurse => true,
  257. }
  258. }
  259. file { "${conf_dir}/sites-enabled/default":
  260. ensure => absent,
  261. }
  262. file { "${conf_dir}/nginx.conf":
  263. ensure => file,
  264. content => template($conf_template),
  265. }
  266. file { "${conf_dir}/conf.d/proxy.conf":
  267. ensure => absent,
  268. }
  269. file { "${conf_dir}/conf.d/default.conf":
  270. ensure => absent,
  271. }
  272. file { "${conf_dir}/conf.d/example_ssl.conf":
  273. ensure => absent,
  274. }
  275. file { "${temp_dir}/nginx.d":
  276. ensure => absent,
  277. purge => true,
  278. recurse => true,
  279. force => true,
  280. }
  281. file { "${temp_dir}/nginx.mail.d":
  282. ensure => absent,
  283. purge => true,
  284. recurse => true,
  285. force => true,
  286. }
  287. }