Saltstack Official Nginx Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 line
13KB

  1. # ========
  2. # nginx (previously named nginx:ng)
  3. # ========
  4. nginx:
  5. # The following three `install_from_` options are mutually exclusive. If none is used, the distro's provided
  6. # package will be installed. If one of the `install_from` option is set to `True`, the state will
  7. # make sure the other two repos are removed.
  8. # Use the official's nginx repo binaries
  9. install_from_repo: false
  10. # Use Phusionpassenger's repo to install nginx and passenger binaries
  11. # Debian, Centos, Ubuntu and Redhat are currently available
  12. install_from_phusionpassenger: false
  13. # PPA install
  14. install_from_ppa: false
  15. # Set to 'stable', 'development' (mainline), 'community', or 'nightly' for each build accordingly ( https://launchpad.net/~nginx )
  16. ppa_version: 'stable'
  17. # Source install
  18. source_version: '1.10.0'
  19. source_hash: ''
  20. # These are usually set by grains in map.jinja
  21. # Typically you can comment these out.
  22. lookup:
  23. package: nginx-custom (can be a list)
  24. service: nginx
  25. webuser: www-data
  26. conf_file: /etc/nginx/nginx.conf
  27. server_available: /etc/nginx/sites-available
  28. server_enabled: /etc/nginx/sites-enabled
  29. server_use_symlink: True
  30. # If you install nginx+passenger from phusionpassenger in Debian, these values will probably be needed
  31. passenger_package: libnginx-mod-http-passenger
  32. passenger_config_file: /etc/nginx/conf.d/mod-http-passenger.conf
  33. # This is required for RedHat like distros (Amazon Linux) that don't follow semantic versioning for $releasever
  34. rh_os_releasever: '6'
  35. # Currently it can be used on rhel/centos/suse when installing from repo
  36. gpg_check: True
  37. pid_file: /var/run/nginx.pid ### prevents rendering SLS error nginx.server.config.pid undefined ###
  38. # Source compilation is not currently a part of nginx
  39. from_source: False
  40. source:
  41. opts: {}
  42. package:
  43. opts: {} # this partially exposes parameters of pkg.installed
  44. service:
  45. enable: True # Whether or not the service will be enabled/running or dead
  46. opts: {} # this partially exposes parameters of service.running / service.dead
  47. ##--- --- - - - - - - -- - - - - -- - - --- -- - -- - - - -- - - - - -- - - - -- - - - -- - ##
  48. ## You can use snippets to define often repeated configuration once and include it later
  49. ## The letsencrypt example below is consumed by "- include: 'snippets/letsencrypt.conf'"
  50. ## Files or Templates can be retrieved by TOFS with snippet name ( Fallback to server.conf )
  51. ##--- --- - - - - - - -- - - -- -- - - --- -- - -- - - - -- - - - - -- - - - -- - - - -- - ##
  52. snippets:
  53. letsencrypt.conf:
  54. - location ^~ /.well-known/acme-challenge/:
  55. - proxy_pass: http://localhost:9999
  56. cloudflare_proxy.conf:
  57. - set_real_ip_from: 103.21.244.0/22
  58. - set_real_ip_from: 103.22.200.0/22
  59. - set_real_ip_from: 104.16.0.0/12
  60. - set_real_ip_from: 108.162.192.0/18
  61. blacklist.conf:
  62. - map $http_user_agent $bad_bot:
  63. - default: 0
  64. - '~*^Lynx': 0
  65. - '~*malicious': 1
  66. - '~*bot': 1
  67. - '~*crawler': 1
  68. - '~*bandit': 1
  69. - libwww-perl: 1
  70. - '~(?i)(httrack|htmlparser|libwww)': 1
  71. upstream_netdata_tcp.conf:
  72. - upstream netdata:
  73. - server: 127.0.0.1:19999
  74. - keepalive: 64
  75. server:
  76. opts: {} # this partially exposes file.managed parameters as they relate to the main nginx.conf file
  77. #-- - - - - -- - - -- - - - - -- - - -- - - - -- - - - - - -- - - - - - -- - - - - -- - - - - -- - - #
  78. # nginx.conf (main server) declarations
  79. # dictionaries map to blocks {} and lists cause the same declaration to repeat with different values
  80. # see also http://nginx.org/en/docs/example.html
  81. # Nginx config file or template can be retrieved by TOFS ( Fallback to nginx.conf )
  82. #-- - - - - -- - - -- - - - - -- - - -- - - - -- - - - - - -- - - - - - -- - - - - -- - - - - -- - - #
  83. config:
  84. include: 'snippets/letsencrypt.conf'
  85. source_path: salt://path_to_nginx_conf_file/nginx.conf # IMPORTANT: This option is mutually exclusive with TOFS and
  86. # the rest of the options; if it is found other options
  87. # (worker_processes: 4 and so on) are not processed
  88. # and just upload the file from source
  89. worker_processes: 4
  90. load_module: modules/ngx_http_lua_module.so # pass as very first in configuration; otherwise nginx will fail to start
  91. #pid: /var/run/nginx.pid # Directory location must exist (i.e. it's /run/nginx.pid on EL7)
  92. events:
  93. worker_connections: 1024
  94. http:
  95. sendfile: 'on'
  96. include:
  97. #### Note: Syntax issues in these files generate nginx [emerg] errors on startup. ####
  98. - /etc/nginx/mime.types
  99. ### module ngx_http_log_module example
  100. log_format: |-
  101. main '$remote_addr - $remote_user [$time_local] $status '
  102. '"$request" $body_bytes_sent "$http_referer" '
  103. '"$http_user_agent" "$http_x_forwarded_for"'
  104. access_log: [] #suppress default access_log option from being added
  105. ### module nngx_stream_core_module
  106. ### https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/#example
  107. stream:
  108. upstream lb-1000:
  109. - server:
  110. - hostname1.example.com:1000
  111. - hostname2.example.com:1000
  112. upstream stream_backend:
  113. least_conn: ''
  114. 'server backend1.example.com:12345 weight=5':
  115. 'server backend2.example.com:12345 max_fails=2 fail_timeout=30s':
  116. 'server backend3.example.com:12345 max_conns=3':
  117. upstream dns_servers:
  118. least_conn:
  119. 'server 192.168.136.130:53':
  120. 'server 192.168.136.131:53':
  121. 'server 192.168.136.132:53':
  122. server:
  123. listen: 1000
  124. proxy_pass: lb-1000
  125. 'server ':
  126. listen: '53 udp'
  127. proxy_pass: dns_servers
  128. 'server ':
  129. listen: 12346
  130. proxy_pass: backend4.example.com:12346
  131. servers:
  132. disabled_postfix: .disabled # a postfix appended to files when doing non-symlink disabling
  133. symlink_opts: {} # partially exposes file.symlink params when symlinking enabled sites
  134. rename_opts: {} # partially exposes file.rename params when not symlinking disabled/enabled sites
  135. managed_opts: {} # partially exposes file.managed params for managed server files
  136. dir_opts: {} # partially exposes file.directory params for site available/enabled and snippets dirs
  137. #####################
  138. # server declarations; placed by default in server "available" directory
  139. #####################
  140. managed:
  141. mysite: # relative filename of server file (defaults to '/etc/nginx/sites-available/mysite')
  142. # may be True, False, or None where True is enabled, False, disabled, and None indicates no action
  143. enabled: True
  144. # Remove the site config file shipped by nginx (i.e. '/etc/nginx/sites-available/default' by default)
  145. # It also remove the symlink (if it is exists).
  146. # The site MUST be disabled before delete it (if not the nginx is not reloaded).
  147. #deleted: True
  148. #available_dir: /etc/nginx/sites-available-custom # custom directory (not sites-available) for server filename
  149. #enabled_dir: /etc/nginx/sites-enabled-custom # custom directory (not sites-enabled) for server filename
  150. disabled_name: mysite.aint_on # an alternative disabled name to be use when not symlinking
  151. overwrite: True # overwrite an existing server file or not
  152. # May be a list of config options or None, if None, no server file will be managed/templated
  153. # Take server directives as lists of dictionaries. If the dictionary value is another list of
  154. # dictionaries a block {} will be started with the dictionary key name
  155. config:
  156. - server:
  157. - server_name: localhost
  158. - listen:
  159. - '80 default_server'
  160. - listen:
  161. - '443 ssl'
  162. - index: 'index.html index.htm'
  163. - location ~ .htm:
  164. - try_files: '$uri $uri/ =404'
  165. - test: something else
  166. - include: 'snippets/letsencrypt.conf'
  167. # Or a slightly more compact alternative syntax:
  168. - server:
  169. - server_name: localhost
  170. - listen:
  171. - '80 default_server'
  172. - '443 ssl'
  173. - index: 'index.html index.htm'
  174. - location ~ .htm:
  175. - try_files: '$uri $uri/ =404'
  176. - test: something else
  177. - include: 'snippets/letsencrypt.conf'
  178. # both of those output:
  179. # server {
  180. # server_name localhost;
  181. # listen 80 default_server;
  182. # listen 443 ssl;
  183. # index index.html index.htm;
  184. # location ~ .htm {
  185. # try_files $uri $uri/ =404;
  186. # test something else;
  187. # }
  188. # }
  189. mysite2: # Using source_path options to upload the file instead of templating all the file
  190. enabled: True
  191. available_dir: /etc/nginx/sites-available
  192. enabled_dir: /etc/nginx/sites-enabled
  193. config:
  194. source_path: salt://path-to-site-file/mysite2 # IMPORTANT: This field is mutually exclusive with TOFS
  195. # and other config options, it just uploads the specified file
  196. # Below configuration becomes handy if you want to create custom configuration files
  197. # for example if you want to create /usr/local/etc/nginx/http_options.conf with
  198. # the following content:
  199. # sendfile on;
  200. # tcp_nopush on;
  201. # tcp_nodelay on;
  202. # send_iowait 12000;
  203. http_options.conf:
  204. enabled: True
  205. available_dir: /usr/local/etc/nginx
  206. enabled_dir: /usr/local/etc/nginx
  207. config:
  208. - sendfile: 'on'
  209. - tcp_nopush: 'on'
  210. - tcp_nodelay: 'on'
  211. - send_iowait: 12000
  212. certificates_path: '/etc/nginx/ssl' # Use this if you need to deploy below certificates in a custom path.
  213. # If you're doing SSL termination, you can deploy certificates this way.
  214. # The private one(s) should go in a separate pillar file not in version
  215. # control (or use encrypted pillar data).
  216. certificates:
  217. 'www.example.com':
  218. # choose one of: deploying this cert by pillar (e.g. in combination with ext_pillar and file_tree)
  219. # public_cert_pillar: certs:example.com:fullchain.pem
  220. # private_key_pillar: certs:example.com:privkey.pem
  221. # or directly pasting the cert
  222. public_cert: |
  223. -----BEGIN CERTIFICATE-----
  224. (Your Primary SSL certificate: www.example.com.crt)
  225. -----END CERTIFICATE-----
  226. -----BEGIN CERTIFICATE-----
  227. (Your Intermediate certificate: ExampleCA.crt)
  228. -----END CERTIFICATE-----
  229. -----BEGIN CERTIFICATE-----
  230. (Your Root certificate: TrustedRoot.crt)
  231. -----END CERTIFICATE-----
  232. private_key: |
  233. -----BEGIN RSA PRIVATE KEY-----
  234. (Your Private Key: www.example.com.key)
  235. -----END RSA PRIVATE KEY-----
  236. dh_param:
  237. 'mydhparam1.pem': |
  238. -----BEGIN DH PARAMETERS-----
  239. (Your custom DH prime)
  240. -----END DH PARAMETERS-----
  241. # or to generate one on-the-fly
  242. 'mydhparam2.pem':
  243. keysize: 2048
  244. # Passenger configuration
  245. # Default passenger configuration is provided, and will be deployed in
  246. # /etc/nginx/conf.d/passenger.conf
  247. # Passenger conf can be retrieved by TOFS ( Fallback to nginx.conf )
  248. passenger:
  249. passenger_root: /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
  250. passenger_ruby: /usr/bin/ruby
  251. passenger_instance_registry_dir: /var/run/passenger-instreg
  252. tofs:
  253. # The files_switch key serves as a selector for alternative
  254. # directories under the formula files directory. See TOFS pattern
  255. # doc for more info.
  256. # Note: Any value not evaluated by `config.get` will be used literally.
  257. # This can be used to set custom paths, as many levels deep as required.
  258. # files_switch:
  259. # - any/path/can/be/used/here
  260. # - id
  261. # - role
  262. # - osfinger
  263. # - os
  264. # - os_family
  265. #
  266. # All aspects of path/file resolution are customisable using the options below.
  267. # This is unnecessary in most cases; there are sensible defaults.
  268. # Path pattern: salt://{{ path_prefix or 'nginx' }}/{{ dirs.files or 'files' }}/{{ dirs.default or 'default' }}
  269. # path_prefix: template_alt
  270. # dirs:
  271. # files: files_alt
  272. # default: default_alt
  273. source_files:
  274. nginx_config_file_managed:
  275. - alt_nginx.conf
  276. passenger_config_file_managed:
  277. - alt_nginx.conf
  278. server_conf_file_managed:
  279. - alt_server.conf
  280. nginx_systemd_service_file:
  281. - alt_nginx.service
  282. nginx_snippet_file_managed:
  283. - alt_server.conf