Created
June 29, 2012 10:10
-
-
Save kucaahbe/3017055 to your computer and use it in GitHub Desktop.
nginx config file for rails + unicorn + gzipped assets + rails caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream rails { | |
server 127.0.0.1:3000; | |
#server unix:/tmp/thin.0.sock; | |
} | |
server { | |
# we haven't checked to see if Rack::Deflate on the app server is | |
# faster or not than doing compression via nginx. It's easier | |
# to configure it all in one place here for static files and also | |
# to disable gzip for clients who don't get gzip/deflate right. | |
# There are other gzip settings that may be needed used to deal with | |
# bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule | |
gzip on; | |
gzip_http_version 1.0; | |
#gzip_proxied any; | |
gzip_min_length 500; | |
gzip_disable "MSIE [1-6]\."; | |
gzip_types text/plain text/html text/xml text/css | |
text/comma-separated-values | |
text/javascript application/x-javascript | |
application/atom+xml; | |
# enable one of the following if you're on Linux or FreeBSD | |
# listen 80 default deferred; # for Linux | |
# listen 80 default accept_filter=httpready; # for FreeBSD | |
listen 80 deferred; | |
server_name FIXME_server_name; | |
access_log logs/rails.access.log; | |
# ~2 seconds is often enough for most folks to parse HTML/CSS and | |
# retrieve needed images/icons/frames, connections are cheap in | |
# nginx so increasing this is generally safe... | |
keepalive_timeout 5; | |
root /path/to/rails/public; | |
# Prefer to serve static files directly from nginx to avoid unnecessary | |
# data copies from the application server. | |
# | |
# try_files directive appeared in in nginx 0.7.27 and has stabilized | |
# over time. Older versions of nginx (e.g. 0.6.x) requires | |
# "if (!-f $request_filename)" which was less efficient: | |
# http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127 | |
try_files $uri/index.html $uri.html $uri @app; | |
location @app { | |
# an HTTP header important enough to have its own Wikipedia entry: | |
# http://en.wikipedia.org/wiki/X-Forwarded-For | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# enable this if you forward HTTPS traffic to unicorn, | |
# this helps Rack set the proper URL scheme for doing redirects: | |
# proxy_set_header X-Forwarded-Proto $scheme; | |
# pass the Host: header from the client right along so redirects | |
# can be set properly within the Rack application | |
proxy_set_header Host $http_host; | |
# we don't want nginx trying to do something clever with | |
# redirects, we set the Host: header above already. | |
proxy_redirect off; | |
# set "proxy_buffering off" *only* for Rainbows! when doing | |
# Comet/long-poll/streaming. It's also safe to set if you're using | |
# only serving fast clients with Unicorn + nginx, but not slow | |
# clients. You normally want nginx to buffer responses to slow | |
# clients, even with Rails 3.1 streaming because otherwise a slow | |
# client can become a bottleneck of Unicorn. | |
# | |
# The Rack application may also set "X-Accel-Buffering (yes|no)" | |
# in the response headers do disable/enable buffering on a | |
# per-response basis. | |
# proxy_buffering off; | |
proxy_pass http://rails; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment