config.pp 9.5 KB

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