doc: remove references to old servers
[unicorn.git] / examples / nginx.conf
blob0583c1fd4ae75a2a37748c6c617f71ae379e7b8d
1 # This is example contains the bare mininum to get nginx going with
2 # unicorn 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
10 # used in its place.
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
17 worker_processes 1;
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
27 pid /path/to/nginx.pid;
28 error_log /path/to/nginx.error.log;
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
37 http {
38   # nginx will find this file in the config directory set at nginx build time
39   include mime.types;
41   # fallback in case we can't determine a type
42   default_type application/octet-stream;
44   # click tracking!
45   access_log /path/to/nginx.access.log combined;
47   # you generally want to serve static files with nginx since
48   # unicorn is not and will never be optimized for it
49   sendfile on;
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 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;
70   # this can be any application server, not just unicorn
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).
76     # for UNIX domain socket setups:
77     server unix:/path/to/.unicorn.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;
83   }
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
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
98     client_max_body_size 4G;
99     server_name _;
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;
106     # path for static files
107     root /path/to/app/current/public;
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;
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;
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;
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;
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;
135       # It's also safe to set if you're using only serving fast clients
136       # with unicorn + nginx, but not slow clients.  You normally want
137       # nginx to buffer responses to slow clients, even with Rails 3.1
138       # streaming because otherwise a slow client can become a bottleneck
139       # of unicorn.
140       #
141       # The Rack application may also set "X-Accel-Buffering (yes|no)"
142       # in the response headers do disable/enable buffering on a
143       # per-response basis.
144       # proxy_buffering off;
146       proxy_pass http://app_server;
147     }
149     # Rails error pages
150     error_page 500 502 503 504 /500.html;
151     location = /500.html {
152       root /path/to/app/current/public;
153     }
154   }