config.pp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. $pid = $nginx::params::pid,
  29. $proxy_temp_path = $nginx::params::proxy_temp_path,
  30. $root_group = $nginx::params::root_group,
  31. $run_dir = $nginx::params::run_dir,
  32. $sites_available_owner = $nginx::params::sites_available_owner,
  33. $sites_available_group = $nginx::params::sites_available_group,
  34. $sites_available_mode = $nginx::params::sites_available_mode,
  35. $super_user = $nginx::params::super_user,
  36. $temp_dir = $nginx::params::temp_dir,
  37. $vhost_purge = false,
  38. # Primary Templates
  39. $conf_template = 'nginx/conf.d/nginx.conf.erb',
  40. $proxy_conf_template = 'nginx/conf.d/proxy.conf.erb',
  41. ### END Module/App Configuration ###
  42. ### START Nginx Configuration ###
  43. $client_body_buffer_size = '128k',
  44. $client_max_body_size = '10m',
  45. $events_use = false,
  46. $fastcgi_cache_inactive = '20m',
  47. $fastcgi_cache_key = false,
  48. $fastcgi_cache_keys_zone = 'd3:100m',
  49. $fastcgi_cache_levels = 1,
  50. $fastcgi_cache_max_size = '500m',
  51. $fastcgi_cache_path = false,
  52. $fastcgi_cache_use_stale = false,
  53. $gzip = 'on',
  54. $http_cfg_append = false,
  55. $http_tcp_nodelay = 'on',
  56. $http_tcp_nopush = 'off',
  57. $keepalive_timeout = 65,
  58. $mail = false,
  59. $multi_accept = 'off',
  60. $names_hash_bucket_size = 64,
  61. $names_hash_max_size = 512,
  62. $proxy_buffers = '32 4k',
  63. $proxy_buffer_size = '8k',
  64. $proxy_cache_inactive = '20m',
  65. $proxy_cache_keys_zone = 'd2:100m',
  66. $proxy_cache_levels = 1,
  67. $proxy_cache_max_size = '500m',
  68. $proxy_cache_path = false,
  69. $proxy_connect_timeout = 90,
  70. $proxy_headers_hash_bucket_size = 64,
  71. $proxy_http_version = '1.0',
  72. $proxy_read_timeout = 90,
  73. $proxy_redirect = 'off',
  74. $proxy_send_timeout = 90,
  75. $proxy_set_header = [
  76. 'Host $host',
  77. 'X-Real-IP $remote_addr',
  78. 'X-Forwarded-For $proxy_add_x_forwarded_for',
  79. ],
  80. $sendfile = 'on',
  81. $server_tokens = 'on',
  82. $spdy = 'off',
  83. $ssl_stapling = 'off',
  84. $types_hash_bucket_size = 512,
  85. $types_hash_max_size = 1024,
  86. $worker_connections = 1024,
  87. $worker_processes = 0,
  88. $worker_rlimit_nofile = 1024,
  89. ### END Nginx Configuration ###
  90. ) {
  91. ### Validations ###
  92. if (!is_string($worker_processes)) and (!is_integer($worker_processes)) {
  93. fail('$worker_processes must be an integer or have value "auto".')
  94. }
  95. if (!is_integer($worker_connections)) {
  96. fail('$worker_connections must be an integer.')
  97. }
  98. if (!is_integer($worker_rlimit_nofile)) {
  99. fail('$worker_rlimit_nofile must be an integer.')
  100. }
  101. if (!is_string($events_use)) and ($events_use != false) {
  102. fail('$events_use must be a string or false.')
  103. }
  104. validate_string($multi_accept)
  105. validate_array($proxy_set_header)
  106. validate_string($proxy_http_version)
  107. validate_bool($confd_purge)
  108. validate_bool($vhost_purge)
  109. if ($proxy_cache_path != false) {
  110. validate_string($proxy_cache_path)
  111. }
  112. validate_re($proxy_cache_levels, '^[12](:[12])*$')
  113. validate_string($proxy_cache_keys_zone)
  114. validate_string($proxy_cache_max_size)
  115. validate_string($proxy_cache_inactive)
  116. if ($fastcgi_cache_path != false) {
  117. validate_string($fastcgi_cache_path)
  118. }
  119. validate_re($fastcgi_cache_levels, '^[12](:[12])*$')
  120. validate_string($fastcgi_cache_keys_zone)
  121. validate_string($fastcgi_cache_max_size)
  122. validate_string($fastcgi_cache_inactive)
  123. if ($fastcgi_cache_key != false) {
  124. validate_string($fastcgi_cache_key)
  125. }
  126. if ($fastcgi_cache_use_stale != false) {
  127. validate_string($fastcgi_cache_use_stale)
  128. }
  129. validate_bool($mail)
  130. validate_string($server_tokens)
  131. validate_string($client_max_body_size)
  132. if (!is_integer($names_hash_bucket_size)) {
  133. fail('$names_hash_bucket_size must be an integer.')
  134. }
  135. if (!is_integer($names_hash_max_size)) {
  136. fail('$names_hash_max_size must be an integer.')
  137. }
  138. validate_string($proxy_buffers)
  139. validate_string($proxy_buffer_size)
  140. if ($http_cfg_append != false) {
  141. if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
  142. fail('$http_cfg_append must be either a hash or array')
  143. }
  144. }
  145. validate_string($nginx_error_log)
  146. validate_string($http_access_log)
  147. validate_string($proxy_headers_hash_bucket_size)
  148. validate_bool($super_user)
  149. ### END VALIDATIONS ###
  150. ### CONFIGURATION ###
  151. File {
  152. owner => $global_owner,
  153. group => $global_group,
  154. mode => $global_mode,
  155. }
  156. file { $conf_dir:
  157. ensure => directory,
  158. }
  159. file { "${conf_dir}/conf.d":
  160. ensure => directory,
  161. }
  162. if $confd_purge == true {
  163. File["${conf_dir}/conf.d"] {
  164. purge => true,
  165. recurse => true,
  166. }
  167. }
  168. file { "${conf_dir}/conf.mail.d":
  169. ensure => directory,
  170. }
  171. if $confd_purge == true {
  172. File["${conf_dir}/conf.mail.d"] {
  173. purge => true,
  174. recurse => true,
  175. }
  176. }
  177. file { "${conf_dir}/conf.d/vhost_autogen.conf":
  178. ensure => absent,
  179. }
  180. file { "${conf_dir}/conf.mail.d/vhost_autogen.conf":
  181. ensure => absent,
  182. }
  183. file {$run_dir:
  184. ensure => directory,
  185. }
  186. file {$client_body_temp_path:
  187. ensure => directory,
  188. owner => $daemon_user,
  189. }
  190. file {$proxy_temp_path:
  191. ensure => directory,
  192. owner => $daemon_user,
  193. }
  194. file { "${conf_dir}/sites-available":
  195. ensure => directory,
  196. owner => $sites_available_owner,
  197. group => $sites_available_group,
  198. mode => $sites_available_mode,
  199. }
  200. if $vhost_purge == true {
  201. File["${conf_dir}/sites-available"] {
  202. purge => true,
  203. recurse => true,
  204. }
  205. }
  206. file { "${conf_dir}/sites-enabled":
  207. ensure => directory,
  208. }
  209. if $vhost_purge == true {
  210. File["${conf_dir}/sites-enabled"] {
  211. purge => true,
  212. recurse => true,
  213. }
  214. }
  215. file { "${conf_dir}/sites-enabled/default":
  216. ensure => absent,
  217. }
  218. file { "${conf_dir}/nginx.conf":
  219. ensure => file,
  220. content => template($conf_template),
  221. }
  222. file { "${conf_dir}/conf.d/proxy.conf":
  223. ensure => file,
  224. content => template($proxy_conf_template),
  225. }
  226. file { "${conf_dir}/conf.d/default.conf":
  227. ensure => absent,
  228. }
  229. file { "${conf_dir}/conf.d/example_ssl.conf":
  230. ensure => absent,
  231. }
  232. file { "${temp_dir}/nginx.d":
  233. ensure => absent,
  234. purge => true,
  235. recurse => true,
  236. force => true,
  237. }
  238. file { "${temp_dir}/nginx.mail.d":
  239. ensure => absent,
  240. purge => true,
  241. recurse => true,
  242. force => true,
  243. }
  244. }