PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/nginx.conf

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