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
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
27 pid /path/to/nginx.pid;
28 error_log /path/to/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 /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
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
60 # https://nginx.org/en/docs/http/ngx_http_gzip_module.html
62 gzip_http_version 1.0;
65 gzip_disable "MSIE [1-6]\.";
66 gzip_types text/plain text/html text/xml text/css
67 text/comma-separated-values
68 text/javascript application/x-javascript
71 # this can be any application server, not just unicorn
73 # fail_timeout=0 means we always retry an upstream even if it failed
74 # to return a good HTTP response (in case the unicorn master nukes a
75 # single worker for timing out).
77 # for UNIX domain socket setups:
78 server unix:/path/to/.unicorn.sock fail_timeout=0;
80 # for TCP setups, point these to your backend servers
81 # server 192.168.0.7:8080 fail_timeout=0;
82 # server 192.168.0.8:8080 fail_timeout=0;
83 # server 192.168.0.9:8080 fail_timeout=0;
87 # enable one of the following if you're on Linux or FreeBSD
88 # listen 80 default deferred; # for Linux
89 # listen 80 default accept_filter=httpready; # for FreeBSD
91 # If you have IPv6, you'll likely want to have two separate listeners.
92 # One on IPv4 only (the default), and another on IPv6 only instead
93 # of a single dual-stack listener. A dual-stack listener will make
94 # for ugly IPv4 addresses in $remote_addr (e.g ":ffff:10.0.0.1"
95 # instead of just "10.0.0.1") and potentially trigger bugs in
97 # listen [::]:80 ipv6only=on; # deferred or accept_filter recommended
99 client_max_body_size 4G;
102 # ~2 seconds is often enough for most folks to parse HTML/CSS and
103 # retrieve needed images/icons/frames, connections are cheap in
104 # nginx so increasing this is generally safe...
107 # path for static files
108 root /path/to/app/current/public;
110 # Prefer to serve static files directly from nginx to avoid unnecessary
111 # data copies from the application server.
113 # try_files directive appeared in in nginx 0.7.27 and has stabilized
114 # over time. Older versions of nginx (e.g. 0.6.x) requires
115 # "if (!-f $request_filename)" which was less efficient:
116 # https://yhbt.net/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
117 try_files $uri/index.html $uri.html $uri @app;
120 # an HTTP header important enough to have its own Wikipedia entry:
121 # https://en.wikipedia.org/wiki/X-Forwarded-For
122 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
124 # enable this if you forward HTTPS traffic to unicorn,
125 # this helps Rack set the proper URL scheme for doing redirects:
126 # proxy_set_header X-Forwarded-Proto $scheme;
128 # pass the Host: header from the client right along so redirects
129 # can be set properly within the Rack application
130 proxy_set_header Host $http_host;
132 # we don't want nginx trying to do something clever with
133 # redirects, we set the Host: header above already.
136 # It's also safe to set if you're using only serving fast clients
137 # with unicorn + nginx, but not slow clients. You normally want
138 # nginx to buffer responses to slow clients, even with Rails 3.1
139 # streaming because otherwise a slow client can become a bottleneck
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;
147 proxy_pass http://app_server;
151 error_page 500 502 503 504 /500.html;
152 location = /500.html {
153 root /path/to/app/current/public;