nginx.conf.j2 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. {% if ansible_prolog -%}
  2. {% from 'templates/ansible/prolog.j2' import prolog with context %}
  3. {{ prolog() }}
  4. {% endif -%}
  5. # nginx Configuration File
  6. # http://wiki.nginx.org/Configuration
  7. # Run as a less privileged user for security reasons.
  8. user www-data;
  9. # How many worker threads to run;
  10. # "auto" sets it to the number of CPU cores available in the system, and
  11. # offers the best performance. Don't set it higher than the number of CPU
  12. # cores if changing this parameter.
  13. # The maximum number of connections for Nginx is calculated by:
  14. # max_clients = worker_processes * worker_connections
  15. worker_processes {{ nginx_workers }};
  16. # Maximum open file descriptors per process;
  17. # should be > worker_connections.
  18. worker_rlimit_nofile 16384;
  19. events {
  20. # When you need > 8000 * cpu_cores connections, you start optimizing your OS,
  21. # and this is probably the point at where you hire people who are smarter than
  22. # you, as this is *a lot* of requests.
  23. worker_connections 4096;
  24. # Event model to use
  25. use epoll;
  26. }
  27. # PID file
  28. pid /var/run/nginx.pid;
  29. http {
  30. # Hide nginx version information.
  31. server_tokens off;
  32. # Define the MIME types for files.
  33. include /etc/nginx/mime.types;
  34. default_type application/octet-stream;
  35. # Format to use in log files
  36. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  37. '$status $body_bytes_sent "$http_referer" '
  38. '"$http_user_agent" "$http_x_forwarded_for"';
  39. # Default log files
  40. # (this is only used when you don't override {error,access}_log on a server{} level)
  41. access_log /var/log/nginx/access.log;
  42. error_log /var/log/nginx/error.log;
  43. # How long to allow each connection to stay idle; longer values are better
  44. # for each individual client, particularly for SSL, but means that worker
  45. # connections are tied up longer. (Default: 65)
  46. keepalive_timeout 20;
  47. # Speed up file transfers by using sendfile() to copy directly
  48. # between descriptors rather than using read()/write().
  49. sendfile on;
  50. # Tell Nginx not to send out partial frames; this increases throughput
  51. # since TCP frames are filled up before being sent out. (adds TCP_CORK)
  52. tcp_nopush on;
  53. # Tell Nginx to enable(off)/disable(on) the Nagle buffering algorithm for TCP packets, which
  54. # collates several smaller packets together into one larger packet, thus saving
  55. # bandwidth at the cost of a nearly imperceptible increase to latency. (removes TCP_NODELAY)
  56. tcp_nodelay on;
  57. # Compression
  58. # Enable Gzip compressed.
  59. gzip on;
  60. # Enable compression both for HTTP/1.0 and HTTP/1.1 (required for CloudFront).
  61. gzip_http_version 1.0;
  62. # Compression level (1-9).
  63. # 5 is a perfect compromise between size and cpu usage, offering about
  64. # 75% reduction for most ascii files (almost identical to level 9).
  65. gzip_comp_level 5;
  66. # Don't compress anything that's already small and unlikely to shrink much
  67. # if at all (the default is 20 bytes, which is bad as that usually leads to
  68. # larger files after gzipping).
  69. gzip_min_length 256;
  70. # Compress data even for clients that are connecting to us via proxies,
  71. # identified by the "Via" header (required for CloudFront).
  72. gzip_proxied any;
  73. # Tell proxies to cache both the gzipped and regular version of a resource
  74. # whenever the client's Accept-Encoding capabilities header varies;
  75. # Avoids the issue where a non-gzip capable client (which is extremely rare
  76. # today) would display gibberish if their proxy gave them the gzipped version.
  77. gzip_vary on;
  78. # Compress all output labeled with one of the following MIME-types.
  79. gzip_types
  80. application/atom+xml
  81. application/javascript
  82. application/x-javascript
  83. application/json
  84. application/rss+xml
  85. application/vnd.ms-fontobject
  86. application/x-font-ttf
  87. application/x-web-app-manifest+json
  88. application/xhtml+xml
  89. application/xml
  90. font/opentype
  91. image/svg+xml
  92. image/x-icon
  93. text/css
  94. text/plain
  95. text/x-component;
  96. # text/html is always compressed by HttpGzipModule
  97. # SSL
  98. # This should be turned on if you are going to have pre-compressed copies (.gz) of
  99. # static files available. If not it should be left off as it will cause extra I/O
  100. # for the check. It is best if you enable this in a location{} block for
  101. # a specific directory, or on an individual server{} level.
  102. # gzip_static on;
  103. # Protect against the BEAST attack by preferring RC4-SHA when using SSLv3 and TLS protocols.
  104. # Note that TLSv1.1 and TLSv1.2 are immune to the beast attack but only work with OpenSSL v1.0.1 and higher and has limited client support.
  105. ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  106. ssl_ciphers RC4:HIGH:!aNULL:!MD5;
  107. ssl_prefer_server_ciphers on;
  108. # Optimize SSL by caching session parameters for 10 minutes. This cuts down on the number of expensive SSL handshakes.
  109. # The handshake is the most CPU-intensive operation, and by default it is re-negotiated on every new/parallel connection.
  110. # By enabling a cache (of type "shared between all Nginx workers"), we tell the client to re-use the already negotiated state.
  111. # Further optimization can be achieved by raising keepalive_timeout, but that shouldn't be done unless you serve primarily HTTPS.
  112. ssl_session_cache shared:SSL:10m; # a 1mb cache can hold about 4000 sessions, so we can hold 40000 sessions
  113. ssl_session_timeout 10m;
  114. # This default SSL certificate will be served whenever the client lacks support for SNI (Server Name Indication).
  115. # 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.
  116. #ssl_certificate /etc/nginx/default_ssl.crt;
  117. #ssl_certificate_key /etc/nginx/default_ssl.key;
  118. # Passenger
  119. #passenger_root /usr;
  120. #passenger_ruby /usr/bin/ruby;
  121. # Naxsi
  122. #include /etc/nginx/naxsi_core.rules;
  123. # Extended configuration
  124. # More configuration parameters
  125. include /etc/nginx/conf.d/*.conf;
  126. # Virtual hosts
  127. include /etc/nginx/sites-enabled/*;
  128. }