Created
January 2, 2012 20:03
-
-
Save jwo/1551895 to your computer and use it in GitHub Desktop.
nginx config for unicorn
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
# you generally only need one nginx worker unless you're serving | |
# large amounts of static files which require blocking disk reads | |
worker_processes 1; | |
user nobody nogroup; # for systems with a "nogroup" | |
pid /tmp/nginx.pid; | |
error_log /tmp/nginx.error.log; | |
events { | |
worker_connections 1024; | |
accept_mutex off; | |
use epoll; # enable for Linux 2.6+ | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay off; | |
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; | |
upstream app_server { | |
server unix:/tmp/.sock fail_timeout=0; | |
} | |
server { | |
client_max_body_size 4G; | |
server_name _; | |
keepalive_timeout 5; | |
root /u/apps/yourappdirectory/current/public; | |
try_files $uri/index.html $uri.html $uri @app; | |
location ~ ^/(assets)/ { | |
root /u/apps/yourappdirectory/current/public; | |
gzip_static on; # to serve pre-gzipped version | |
expires max; | |
add_header Cache-Control public; | |
} | |
location @app { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# enable this if and only if you use HTTPS, this helps Rack | |
# set the proper protocol for doing redirects: | |
# proxy_set_header X-Forwarded-Proto https; | |
# 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://app_server; | |
} | |
# Rails error pages | |
error_page 500 502 503 504 /500.html; | |
location = /500.html { | |
root /u/apps/yourappdirectory/current/public; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment