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.

config.jinja 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {% set nginx = pillar.get('nginx', {}) -%}
  2. {% set user = nginx.get('user', 'www-data') -%}
  3. {% set group = nginx.get('group', 'www-data') -%}
  4. user {{ user }} {{ group }};
  5. worker_processes {{ nginx.get('worker_processes', 1) }};
  6. {% set worker_rlimit_nofile = nginx.get('worker_rlimit_nofile', '') -%}
  7. {% if worker_rlimit_nofile -%}
  8. worker_rlimit_nofile {{ worker_rlimit_nofile }};
  9. {% endif -%}
  10. error_log /var/log/nginx/error.fifo warn;
  11. pid {{ nginx.get('pid', '/var/run/nginx.pid') }};
  12. daemon {{ nginx.get('daemon', 'off') }};
  13. events {
  14. worker_connections {{ nginx.get('events', {}).get('worker_connections', 1024) }};
  15. {% set use = nginx.get('events', {}).get('use', '') -%}
  16. {% if use -%}
  17. use {{ use }};
  18. {% endif -%}}
  19. }
  20. http {
  21. include /etc/nginx/mime.types;
  22. default_type application/octet-stream;
  23. log_format main '$scheme://$host:$server_port$uri$is_args$args $remote_addr:$remote_user "$request" $request_time $request_length:$bytes_sent $status "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
  24. access_log /var/log/nginx/access.fifo main;
  25. sendfile {{ nginx.get('sendfile', 'on') }};
  26. #tcp_nopush on;
  27. keepalive_timeout {{ nginx.get('keepalive_timeout', 65) }};
  28. server_names_hash_bucket_size {{ nginx.get('server_names_hash_bucket_size', 128) }};
  29. server_names_hash_max_size {{ nginx.get('server_names_hash_max_size', 1024) }};
  30. types_hash_max_size {{ nginx.get('types_hash_max_size', 8192) }};
  31. gzip {{ nginx.get('gzip', 'on') }};
  32. gzip_vary {{ nginx.get('gzip_vary', 'on') }};
  33. gzip_proxied {{ nginx.get('gzip_proxied', 'any') }};
  34. gzip_comp_level {{ nginx.get('gzip_comp_level', 6) }};
  35. gzip_buffers {{ nginx.get('gzip_buffers', '16 8k') }};
  36. gzip_http_version {{ nginx.get('gzip_http_version', '1.1') }};
  37. gzip_types {{ nginx.get('gzip_types', ['text/plain', 'text/css', 'application/json', 'application/x-javascript', 'text/xml', 'application/xml', 'application/xml+rss', 'text/javascript'])|join(' ') }};
  38. # turn on nginx_status on localhost
  39. server {
  40. listen 127.0.0.1:80;
  41. server_name 127.0.0.1;
  42. location /nginx_status {
  43. stub_status on;
  44. access_log off;
  45. allow 127.0.0.1;
  46. deny all;
  47. }
  48. }
  49. {% if pillar['nginx'] is defined -%}
  50. {% if pillar['nginx']['redirect_numeric_ip']|default(False) %}
  51. server {
  52. server_name {% for ip in salt['network.interfaces']()['eth0']['inet'] %}{{ ip['address'] }}:80{% if not loop.last %} {% endif %}{% endfor %};
  53. return 302 {{ pillar['nginx']['redirect_numeric_ip'] }};
  54. access_log off;
  55. }
  56. {% endif %}
  57. {% endif %}
  58. include /etc/nginx/conf.d/*.conf;
  59. include /etc/nginx/sites-enabled/*.conf;
  60. }