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 # listen 80 default deferred; # for Linux
87 # 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;
102 # an HTTP header important enough to have its own Wikipedia entry:
103 # http://en.wikipedia.org/wiki/X-Forwarded-For
104 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
106 # enable this if and only if you use HTTPS, this helps Rack
107 # set the proper protocol for doing redirects:
108 # proxy_set_header X-Forwarded-Proto https;
110 # pass the Host: header from the client right along so redirects
111 # can be set properly within the Rack application
112 proxy_set_header Host $http_host;
114 # we don't want nginx trying to do something clever with
115 # redirects, we set the Host: header above already.
118 # set "proxy_buffering off" *only* for Rainbows! when doing
119 # Comet/long-poll stuff. It's also safe to set if you're
120 # using only serving fast clients with Unicorn + nginx.
121 # Otherwise you _want_ nginx to buffer responses to slow
123 # proxy_buffering off;
125 # Try to serve static files from nginx, no point in making an
126 # *application* server like Unicorn/Rainbows! serve static files.
127 if (!-f $request_filename) {
128 proxy_pass http://app_server;
134 error_page 500 502 503 504 /500.html;
135 location = /500.html {
136 root /path/to/app/current/public;