nginx.conf 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # This is example contains the bare mininum to get nginx going with
  2. # Unicorn or Rainbows! servers. Generally these configuration settings
  3. # are applicable to other HTTP application servers (and not just Ruby
  4. # ones), so if you have one working well for proxying another app
  5. # server, feel free to continue using it.
  6. #
  7. # The only setting we feel strongly about is the fail_timeout=0
  8. # directive in the "upstream" block. max_fails=0 also has the same
  9. # effect as fail_timeout=0 for current versions of nginx and may be
  10. # used in its place.
  11. #
  12. # Users are strongly encouraged to refer to nginx documentation for more
  13. # details and search for other example configs.
  14. # you generally only need one nginx worker unless you're serving
  15. # large amounts of static files which require blocking disk reads
  16. worker_processes 8;
  17. # # drop privileges, root is needed on most systems for binding to port 80
  18. # # (or anything < 1024). Capability-based security may be available for
  19. # # your system and worth checking out so you won't need to be root to
  20. # # start nginx to bind on 80
  21. # user nobody nogroup; # for systems with a "nogroup"
  22. #user nobody nobody; # for systems with "nobody" as a group instead
  23. # Feel free to change all paths to suite your needs here, of course
  24. pid /tmp/nginx.pid;
  25. #error_log /tmp/nginx.error.log;
  26. error_log stderr error;
  27. events {
  28. worker_connections 4096; # increase if you have lots of clients
  29. accept_mutex off; # "on" if nginx worker_processes > 1
  30. use epoll; # enable for Linux 2.6+
  31. # use kqueue; # enable for FreeBSD, OSX
  32. }
  33. http {
  34. # nginx will find this file in the config directory set at nginx build time
  35. include /etc/nginx/mime.types;
  36. # fallback in case we can't determine a type
  37. default_type application/octet-stream;
  38. # click tracking!
  39. #access_log /tmp/nginx.access.log combined;
  40. access_log off;
  41. # you generally want to serve static files with nginx since neither
  42. # Unicorn nor Rainbows! is optimized for it at the moment
  43. sendfile on;
  44. tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
  45. tcp_nodelay off; # on may be better for some Comet/long-poll stuff
  46. # we haven't checked to see if Rack::Deflate on the app server is
  47. # faster or not than doing compression via nginx. It's easier
  48. # to configure it all in one place here for static files and also
  49. # to disable gzip for clients who don't get gzip/deflate right.
  50. # There are other gzip settings that may be needed used to deal with
  51. # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule
  52. #gzip on;
  53. #gzip_http_version 1.0;
  54. #gzip_proxied any;
  55. #gzip_min_length 500;
  56. #gzip_disable "MSIE [1-6]\.";
  57. #gzip_types text/plain text/html text/xml text/css
  58. # text/comma-separated-values
  59. # text/javascript application/x-javascript
  60. # application/atom+xml;
  61. # this can be any application server, not just Unicorn/Rainbows!
  62. upstream app_server {
  63. # fail_timeout=0 means we always retry an upstream even if it failed
  64. # to return a good HTTP response (in case the Unicorn master nukes a
  65. # single worker for timing out).
  66. # for UNIX domain socket setups:
  67. server unix:/tmp/.sock fail_timeout=0;
  68. # for TCP setups, point these to your backend servers
  69. # server 192.168.0.7:8080 fail_timeout=0;
  70. # server 192.168.0.8:8080 fail_timeout=0;
  71. # server 192.168.0.9:8080 fail_timeout=0;
  72. }
  73. server {
  74. # enable one of the following if you're on Linux or FreeBSD
  75. listen 8080 default deferred; # for Linux
  76. # listen 80 default accept_filter=httpready; # for FreeBSD
  77. # If you have IPv6, you'll likely want to have two separate listeners.
  78. # One on IPv4 only (the default), and another on IPv6 only instead
  79. # of a single dual-stack listener. A dual-stack listener will make
  80. # for ugly IPv4 addresses in $remote_addr (e.g ":ffff:10.0.0.1"
  81. # instead of just "10.0.0.1") and potentially trigger bugs in
  82. # some software.
  83. # listen [::]:80 ipv6only=on; # deferred or accept_filter recommended
  84. client_max_body_size 4G;
  85. server_name _;
  86. # ~2 seconds is often enough for most folks to parse HTML/CSS and
  87. # retrieve needed images/icons/frames, connections are cheap in
  88. # nginx so increasing this is generally safe...
  89. keepalive_timeout 10;
  90. # path for static files
  91. root /path/to/app/current/public;
  92. # Prefer to serve static files directly from nginx to avoid unnecessary
  93. # data copies from the application server.
  94. #
  95. # try_files directive appeared in in nginx 0.7.27 and has stabilized
  96. # over time. Older versions of nginx (e.g. 0.6.x) requires
  97. # "if (!-f $request_filename)" which was less efficient:
  98. # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
  99. try_files $uri/index.html $uri.html $uri @app;
  100. location @app {
  101. # an HTTP header important enough to have its own Wikipedia entry:
  102. # http://en.wikipedia.org/wiki/X-Forwarded-For
  103. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  104. # enable this if you forward HTTPS traffic to unicorn,
  105. # this helps Rack set the proper URL scheme for doing redirects:
  106. # proxy_set_header X-Forwarded-Proto $scheme;
  107. # pass the Host: header from the client right along so redirects
  108. # can be set properly within the Rack application
  109. proxy_set_header Host $http_host;
  110. # we don't want nginx trying to do something clever with
  111. # redirects, we set the Host: header above already.
  112. proxy_redirect off;
  113. # set "proxy_buffering off" *only* for Rainbows! when doing
  114. # Comet/long-poll/streaming. It's also safe to set if you're using
  115. # only serving fast clients with Unicorn + nginx, but not slow
  116. # clients. You normally want nginx to buffer responses to slow
  117. # clients, even with Rails 3.1 streaming because otherwise a slow
  118. # client can become a bottleneck of Unicorn.
  119. #
  120. # The Rack application may also set "X-Accel-Buffering (yes|no)"
  121. # in the response headers do disable/enable buffering on a
  122. # per-response basis.
  123. # proxy_buffering off;
  124. proxy_pass http://app_server;
  125. }
  126. # Rails error pages
  127. error_page 500 502 503 504 /500.html;
  128. location = /500.html {
  129. root /path/to/app/current/public;
  130. }
  131. }
  132. }