nginx.conf 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # Set another default user than root for security reasons
  2. user www www;
  3. # As a thumb rule: One per CPU. If you are serving a large amount
  4. # of static files, which requires blocking disk reads, you may want
  5. # to increase this from the number of cpu_cores available on your
  6. # system.
  7. #
  8. # The maximum number of connections for Nginx is calculated by:
  9. # max_clients = worker_processes * worker_connections
  10. worker_processes 1;
  11. # Maximum file descriptors that can be opened per process
  12. # This should be > worker_connections
  13. worker_rlimit_nofile 8192;
  14. events {
  15. # When you need > 8000 * cpu_cores connections, you start optimizing
  16. # your OS, and this is probably the point at where you hire people
  17. # who are smarter than you, this is *a lot* of requests.
  18. worker_connections 8000;
  19. }
  20. # Change these paths to somewhere that suits you!
  21. error_log logs/error.log;
  22. pid logs/nginx.pid;
  23. http {
  24. # Set the mime-types via the mime.types external file
  25. include nginx-mime.types;
  26. # And the fallback mime-type
  27. default_type application/octet-stream;
  28. # Format for our log files
  29. log_format main '$remote_addr - $remote_user [$time_local] $status '
  30. '"$request" $body_bytes_sent "$http_referer" '
  31. '"$http_user_agent" "$http_x_forwarded_for"';
  32. # Click tracking!
  33. access_log logs/access.log main;
  34. # ~2 seconds is often enough for HTML/CSS, but connections in
  35. # Nginx are cheap, so generally it's safe to increase it
  36. keepalive_timeout 20;
  37. # You usually want to serve static files with Nginx
  38. sendfile on;
  39. tcp_nopush on; # off may be better for Comet/long-poll stuff
  40. tcp_nodelay off; # on may be better for Comet/long-poll stuff
  41. # Enable Gzip:
  42. gzip on;
  43. gzip_http_version 1.0;
  44. gzip_comp_level 5;
  45. gzip_min_length 512;
  46. gzip_buffers 4 8k;
  47. gzip_proxied any;
  48. gzip_types
  49. # text/html is always compressed by HttpGzipModule
  50. text/css
  51. text/javascript
  52. text/xml
  53. text/plain
  54. text/x-component
  55. application/javascript
  56. application/json
  57. application/xml
  58. application/rss+xml
  59. font/truetype
  60. font/opentype
  61. application/vnd.ms-fontobject
  62. image/svg+xml;
  63. # This should be turned on if you are going to have pre-compressed copies (.gz) of
  64. # static files available. If not it should be left off as it will cause extra I/O
  65. # for the check. It would be better to enable this in a location {} block for
  66. # a specific directory:
  67. # gzip_static on;
  68. gzip_disable "MSIE [1-6]\.";
  69. gzip_vary on;
  70. server {
  71. # listen 80 default_server deferred; # for Linux
  72. # listen 80 default_server accept_filter=httpready; # for FreeBSD
  73. listen 80 default_server;
  74. # e.g. "localhost" to accept all connections, or "www.example.com"
  75. # to handle the requests for "example.com" (and www.example.com)
  76. # server_name www.example.com;
  77. # Path for static files
  78. root /sites/example.com/public;
  79. # Custom 404 page
  80. error_page 404 /404.html;
  81. # This is pretty long expiry and assume your using
  82. # cachebusting with query params like
  83. # <script src="application.js?20110529">
  84. #
  85. # Just be careful if your using this on a frequently
  86. # updated static site. You may want to crank this back
  87. # to 5m which is 5 minutes.
  88. expires 1M; # yes one month
  89. # Static assets
  90. location ~* ^.+\.(manifest|appcache)$ {
  91. expires -1;
  92. access_log logs/static.log;
  93. }
  94. # Set expires max on static file types (make sure you are using cache busting filenames or query params):
  95. location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
  96. expires max;
  97. access_log off;
  98. }
  99. # opt-in to the future
  100. add_header "X-UA-Compatible" "IE=Edge,chrome=1";
  101. }
  102. }