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.

396 lines
15KB

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