Advertisement
tblanko

Untitled

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