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.
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
12 # Users are strongly encouraged to refer to nginx documentation for more
13 # details and search for other example configs.
15 # you generally only need one nginx worker unless you're serving
16 # large amounts of static files which require blocking disk reads
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 nobody nogroup; # for systems with a "nogroup"
24 # user nobody nobody; # for systems with "nobody" as a group instead
26 # Feel free to change all paths to suite your needs here, of course
28 error_log /tmp/nginx.error.log;
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
38 # nginx will find this file in the config directory set at nginx build time
41 # fallback in case we can't determine a type
42 default_type application/octet-stream;
45 access_log /tmp/nginx.access.log combined;
47 # you generally want to serve static files with nginx since neither
48 # Unicorn nor Rainbows! is optimized for it at the moment
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
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 other gzip settings that may be needed used to deal with
59 # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule
61 gzip_http_version 1.0;
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
70 # this can be any application server, not just Unicorn/Rainbows!
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).
76 # for UNIX domain socket setups:
77 server unix:/tmp/.sock fail_timeout=0;
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;
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
90 client_max_body_size 4G;
93 # ~2 seconds is often enough for most folks to parse HTML/CSS and
94 # retrieve needed images/icons/frames, connections are cheap in
95 # nginx so increasing this is generally safe...
98 # path for static files
99 root /path/to/app/current/public;
101 # Prefer to serve static files directly from nginx to avoid unnecessary
102 # data copies from the application server.
104 # try_files directive appeared in in nginx 0.7.27 and has stabilized
105 # over time. Older versions of nginx (e.g. 0.6.x) requires
106 # "if (!-f $request_filename)" which was less efficient:
107 # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
108 try_files $uri/index.html $uri.html $uri @app;
111 # an HTTP header important enough to have its own Wikipedia entry:
112 # http://en.wikipedia.org/wiki/X-Forwarded-For
113 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
115 # enable this if and only if you use HTTPS, this helps Rack
116 # set the proper protocol for doing redirects:
117 # proxy_set_header X-Forwarded-Proto https;
119 # pass the Host: header from the client right along so redirects
120 # can be set properly within the Rack application
121 proxy_set_header Host $http_host;
123 # we don't want nginx trying to do something clever with
124 # redirects, we set the Host: header above already.
127 # set "proxy_buffering off" *only* for Rainbows! when doing
128 # Comet/long-poll/streaming. It's also safe to set if you're using
129 # only serving fast clients with Unicorn + nginx, but not slow
130 # clients. You normally want nginx to buffer responses to slow
131 # clients, even with Rails 3.1 streaming because otherwise a slow
132 # client can become a bottleneck of Unicorn.
134 # The Rack application may also set "X-Accel-Buffering (yes|no)"
135 # in the response headers do disable/enable buffering on a
136 # per-response basis.
137 # proxy_buffering off;
139 proxy_pass http://app_server;
143 error_page 500 502 503 504 /500.html;
144 location = /500.html {
145 root /path/to/app/current/public;