nginx.conf.j2 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. {% if ansible_controlled is defined and ansible_controlled != "" %}
  2. #
  3. # {{ ansible_controlled }}
  4. #
  5. {% endif %}
  6. # nginx Configuration File
  7. # http://wiki.nginx.org/Configuration
  8. # Run as a less privileged user for security reasons.
  9. user www-data;
  10. # How many worker threads to run;
  11. # "auto" sets it to the number of CPU cores available in the system, and
  12. # offers the best performance. Don't set it higher than the number of CPU
  13. # cores if changing this parameter.
  14. # The maximum number of connections for Nginx is calculated by:
  15. # max_clients = worker_processes * worker_connections
  16. worker_processes {{ nginx_workers }};
  17. # Maximum open file descriptors per process;
  18. # should be > worker_connections.
  19. worker_rlimit_nofile 16384;
  20. events {
  21. # When you need > 8000 * cpu_cores connections, you start optimizing your OS,
  22. # and this is probably the point at where you hire people who are smarter than
  23. # you, as this is *a lot* of requests.
  24. worker_connections 4096;
  25. # Event model to use
  26. use epoll;
  27. }
  28. # PID file
  29. pid /run/nginx.pid;
  30. http {
  31. ### Global settings ###
  32. # Hide nginx version information.
  33. server_tokens off;
  34. # How long to allow each connection to stay idle; longer values are better
  35. # for each individual client, particularly for SSL, but means that worker
  36. # connections are tied up longer. (Default: 65)
  37. keepalive_timeout 60 60;
  38. # Speed up file transfers by using sendfile() to copy directly
  39. # between descriptors rather than using read()/write().
  40. sendfile on;
  41. # Tell Nginx not to send out partial frames; this increases throughput
  42. # since TCP frames are filled up before being sent out. (adds TCP_CORK)
  43. tcp_nopush on;
  44. # Tell Nginx to enable(off)/disable(on) the Nagle buffering algorithm for TCP packets, which
  45. # collates several smaller packets together into one larger packet, thus saving
  46. # bandwidth at the cost of a nearly imperceptible increase to latency. (removes TCP_NODELAY)
  47. tcp_nodelay on;
  48. # Specifies the maximum accepted body size of a client request, as
  49. # indicated by the request header Content-Length (0 to disable)
  50. client_max_body_size 4m;
  51. # Directive assigns the maximum number and size of buffers for large
  52. # headers to read from client request.
  53. large_client_header_buffers 8 8k;
  54. # Directive sets the headerbuffer size for the request header from client.
  55. # For the overwhelming majority of requests it is completely sufficient
  56. # with a buffer size of 1K
  57. client_header_buffer_size 4k;
  58. ### Define the MIME types for files ###
  59. include /etc/nginx/mime.types;
  60. include /etc/nginx/mime.types.custom;
  61. default_type application/octet-stream;
  62. # Format to use in log files
  63. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  64. '$status $body_bytes_sent "$http_referer" '
  65. '"$http_user_agent" "$http_x_forwarded_for" '
  66. '$host ${request_time} ${scheme}';
  67. ### Default log files ###
  68. # (this is only used when you don't override {error,access}_log on a server{} level)
  69. access_log /var/log/nginx/access.log;
  70. error_log /var/log/nginx/error.log;
  71. # Compression
  72. # Enable Gzip compressed.
  73. gzip on;
  74. # Enable compression both for HTTP/1.0 and HTTP/1.1 (required for CloudFront).
  75. gzip_http_version 1.0;
  76. # Compression level (1-9).
  77. # 5 is a perfect compromise between size and cpu usage, offering about
  78. # 75% reduction for most ascii files (almost identical to level 9).
  79. gzip_comp_level 5;
  80. # Don't compress anything that's already small and unlikely to shrink much
  81. # if at all (the default is 20 bytes, which is bad as that usually leads to
  82. # larger files after gzipping).
  83. gzip_min_length 256;
  84. # Compress data even for clients that are connecting to us via proxies,
  85. # identified by the "Via" header (required for CloudFront).
  86. gzip_proxied any;
  87. # Tell proxies to cache both the gzipped and regular version of a resource
  88. # whenever the client's Accept-Encoding capabilities header varies;
  89. # Avoids the issue where a non-gzip capable client (which is extremely rare
  90. # today) would display gibberish if their proxy gave them the gzipped version.
  91. gzip_vary on;
  92. # Compress all output labeled with one of the following MIME-types.
  93. gzip_types
  94. application/atom+xml
  95. application/javascript
  96. application/x-javascript
  97. application/json
  98. application/rss+xml
  99. application/vnd.ms-fontobject
  100. application/x-font-ttf
  101. application/x-web-app-manifest+json
  102. application/xhtml+xml
  103. application/xml
  104. font/opentype
  105. image/svg+xml
  106. image/x-icon
  107. text/css
  108. text/plain
  109. text/x-component;
  110. # text/html is always compressed by HttpGzipModule
  111. # This should be turned on if you are going to have pre-compressed copies (.gz) of
  112. # static files available. If not it should be left off as it will cause extra I/O
  113. # for the check. It is best if you enable this in a location{} block for
  114. # a specific directory, or on an individual server{} level.
  115. # gzip_static on;
  116. ### SSL ###
  117. # Diffie-Hellman parameter for DHE ciphersuites
  118. ssl_dhparam /etc/ssl/private/dh2048.pem;
  119. {% if nginx_ssl_strengthened %}
  120. ssl_protocols TLSv1.2;
  121. ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
  122. {% else %}
  123. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  124. ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
  125. {% endif %}
  126. ssl_prefer_server_ciphers on;
  127. # Optimize SSL by caching session parameters for 5 minutes. This cuts down on the number of expensive SSL handshakes.
  128. # The handshake is the most CPU-intensive operation, and by default it is re-negotiated on every new/parallel connection.
  129. # By enabling a cache (of type "shared between all Nginx workers"), we tell the client to re-use the already negotiated state.
  130. # Further optimization can be achieved by raising keepalive_timeout, but that shouldn't be done unless you serve primarily HTTPS.
  131. ssl_session_cache shared:SSL:10m; # a 1mb cache can hold about 4000 sessions, so we can hold 40000 sessions
  132. ssl_session_timeout 5m;
  133. ssl_session_tickets off;
  134. # This default SSL certificate will be served whenever the client lacks support for SNI (Server Name Indication).
  135. # Make it a symlink to the most important certificate you have, so that users of IE 8 and below on WinXP can see your main site without SSL errors.
  136. #ssl_certificate /etc/nginx/default_ssl.crt;
  137. #ssl_certificate_key /etc/nginx/default_ssl.key;
  138. ### Passenger ###
  139. #passenger_root /usr;
  140. #passenger_ruby /usr/bin/ruby;
  141. ### Extended configuration ###
  142. {% if nginx_http_config %}
  143. # Custom settings
  144. {%for param in nginx_http_config %}
  145. {{ param }} {{ nginx_http_config[param] }};
  146. {% endfor %}
  147. {% endif %}
  148. # More configuration parameters
  149. include /etc/nginx/conf.d/*.conf;
  150. # Virtual hosts inclusion
  151. include /etc/nginx/sites-enabled/*;
  152. }
  153. #
  154. # Include more global diretives (mail, rtmp, etc.)
  155. #
  156. include /etc/nginx/conf.d/*.inc;