config.pp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. 'Proxy ""',
  94. ],
  95. $proxy_hide_header = [],
  96. $sendfile = 'on',
  97. $server_tokens = 'on',
  98. $spdy = 'off',
  99. $http2 = 'off',
  100. $ssl_stapling = 'off',
  101. $types_hash_bucket_size = '512',
  102. $types_hash_max_size = '1024',
  103. $worker_connections = '1024',
  104. $worker_processes = '1',
  105. $worker_rlimit_nofile = '1024',
  106. ### END Nginx Configuration ###
  107. ) inherits ::nginx::params {
  108. ### Validations ###
  109. if ($worker_processes != 'auto') and (!is_integer($worker_processes)) {
  110. fail('$worker_processes must be an integer or have value "auto".')
  111. }
  112. if (!is_integer($worker_connections)) {
  113. fail('$worker_connections must be an integer.')
  114. }
  115. if (!is_integer($worker_rlimit_nofile)) {
  116. fail('$worker_rlimit_nofile must be an integer.')
  117. }
  118. if (!is_string($events_use)) and ($events_use != false) {
  119. fail('$events_use must be a string or false.')
  120. }
  121. validate_string($multi_accept)
  122. validate_array($proxy_set_header)
  123. validate_array($proxy_hide_header)
  124. if ($proxy_http_version != undef) {
  125. validate_string($proxy_http_version)
  126. }
  127. if ($proxy_conf_template != undef) {
  128. warning('The $proxy_conf_template parameter is deprecated and has no effect.')
  129. }
  130. validate_bool($confd_purge)
  131. validate_bool($vhost_purge)
  132. if ( $proxy_cache_path != false) {
  133. if ( is_string($proxy_cache_path) or is_hash($proxy_cache_path)) {}
  134. else {
  135. fail('proxy_cache_path must be a string or a hash')
  136. }
  137. }
  138. validate_re($proxy_cache_levels, '^[12](:[12])*$')
  139. validate_string($proxy_cache_keys_zone)
  140. validate_string($proxy_cache_max_size)
  141. validate_string($proxy_cache_inactive)
  142. if ($fastcgi_cache_path != false) {
  143. validate_string($fastcgi_cache_path)
  144. }
  145. validate_re($fastcgi_cache_levels, '^[12](:[12])*$')
  146. validate_string($fastcgi_cache_keys_zone)
  147. validate_string($fastcgi_cache_max_size)
  148. validate_string($fastcgi_cache_inactive)
  149. if ($fastcgi_cache_key != false) {
  150. validate_string($fastcgi_cache_key)
  151. }
  152. if ($fastcgi_cache_use_stale != false) {
  153. validate_string($fastcgi_cache_use_stale)
  154. }
  155. validate_bool($mail)
  156. validate_string($server_tokens)
  157. validate_string($client_max_body_size)
  158. if (!is_integer($names_hash_bucket_size)) {
  159. fail('$names_hash_bucket_size must be an integer.')
  160. }
  161. if (!is_integer($names_hash_max_size)) {
  162. fail('$names_hash_max_size must be an integer.')
  163. }
  164. validate_string($proxy_buffers)
  165. validate_string($proxy_buffer_size)
  166. if ($http_cfg_append != false) {
  167. if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
  168. fail('$http_cfg_append must be either a hash or array')
  169. }
  170. }
  171. if ($nginx_cfg_prepend != false) {
  172. if !(is_hash($nginx_cfg_prepend) or is_array($nginx_cfg_prepend)) {
  173. fail('$nginx_cfg_prepend must be either a hash or array')
  174. }
  175. }
  176. validate_string($nginx_error_log)
  177. 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')
  178. validate_string($http_access_log)
  179. validate_string($proxy_headers_hash_bucket_size)
  180. validate_bool($super_user)
  181. ### END VALIDATIONS ###
  182. ### CONFIGURATION ###
  183. File {
  184. owner => $global_owner,
  185. group => $global_group,
  186. mode => $global_mode,
  187. }
  188. file { $conf_dir:
  189. ensure => directory,
  190. }
  191. file { "${conf_dir}/conf.stream.d":
  192. ensure => directory,
  193. }
  194. if $confd_purge == true {
  195. File["${conf_dir}/conf.stream.d"] {
  196. purge => true,
  197. recurse => true,
  198. }
  199. }
  200. file { "${conf_dir}/conf.d":
  201. ensure => directory,
  202. }
  203. if $confd_purge == true {
  204. File["${conf_dir}/conf.d"] {
  205. purge => true,
  206. recurse => true,
  207. notify => Class['::nginx::service'],
  208. }
  209. }
  210. file { "${conf_dir}/conf.mail.d":
  211. ensure => directory,
  212. }
  213. if $confd_purge == true {
  214. File["${conf_dir}/conf.mail.d"] {
  215. purge => true,
  216. recurse => true,
  217. }
  218. }
  219. file { "${conf_dir}/conf.d/vhost_autogen.conf":
  220. ensure => absent,
  221. }
  222. file { "${conf_dir}/conf.mail.d/vhost_autogen.conf":
  223. ensure => absent,
  224. }
  225. file {$run_dir:
  226. ensure => directory,
  227. }
  228. file { $log_dir:
  229. ensure => directory,
  230. }
  231. file {$client_body_temp_path:
  232. ensure => directory,
  233. owner => $daemon_user,
  234. }
  235. file {$proxy_temp_path:
  236. ensure => directory,
  237. owner => $daemon_user,
  238. }
  239. file { "${conf_dir}/sites-available":
  240. ensure => directory,
  241. owner => $sites_available_owner,
  242. group => $sites_available_group,
  243. mode => $sites_available_mode,
  244. }
  245. if $vhost_purge == true {
  246. File["${conf_dir}/sites-available"] {
  247. purge => true,
  248. recurse => true,
  249. }
  250. }
  251. file { "${conf_dir}/sites-enabled":
  252. ensure => directory,
  253. }
  254. if $vhost_purge == true {
  255. File["${conf_dir}/sites-enabled"] {
  256. purge => true,
  257. recurse => true,
  258. }
  259. }
  260. file { "${conf_dir}/sites-enabled/default":
  261. ensure => absent,
  262. }
  263. file { "${conf_dir}/nginx.conf":
  264. ensure => file,
  265. content => template($conf_template),
  266. }
  267. file { "${conf_dir}/conf.d/proxy.conf":
  268. ensure => absent,
  269. }
  270. file { "${conf_dir}/conf.d/default.conf":
  271. ensure => absent,
  272. }
  273. file { "${conf_dir}/conf.d/example_ssl.conf":
  274. ensure => absent,
  275. }
  276. file { "${temp_dir}/nginx.d":
  277. ensure => absent,
  278. purge => true,
  279. recurse => true,
  280. force => true,
  281. }
  282. file { "${temp_dir}/nginx.mail.d":
  283. ensure => absent,
  284. purge => true,
  285. recurse => true,
  286. force => true,
  287. }
  288. }