Last active
September 28, 2015 13:08
-
-
Save manchunlam/1443424 to your computer and use it in GitHub Desktop.
Sample Nginx Configuration 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
#user nobody; | |
worker_processes 1; | |
error_log /usr/local/etc/nginx/logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
pid /usr/local/etc/nginx/logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /usr/local/etc/nginx/logs/access.log main; | |
# enable directory listing | |
autoindex on; | |
# no sendfile on OS X | |
sendfile on; | |
# these are good default values | |
tcp_nopush on; | |
tcp_nodelay off; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
# passenger_root /Users/joelam/.rvm/gems/ruby-1.9.2-p290@global/gems/passenger-3.0.9; | |
# passenger_ruby /Users/joelam/.rvm/wrappers/ruby-1.9.2-p290@global/ruby; | |
# output compression saves bandwidth | |
# gzip on; | |
# gzip_http_version 1.0; | |
# gzip_comp_level 2; | |
# gzip_proxied any; | |
# gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
# server files (aka. VirtualHosts) | |
include /usr/local/etc/nginx/sites-enabled/*; | |
} |
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 tabs { | |
server unix:/Users/joelam/Products/tabs/tmp/sockets/unicorn.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
client_max_body_size 4G; | |
server_name tabs.joelam.dev; | |
# ~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; | |
# path to static files | |
root /Users/joelam/Products/tabs/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; | |
access_log /Users/joelam/Products/tabs/log/access.log; | |
error_log /Users/joelam/Products/tabs/log/error.log; | |
location / { | |
# 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 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://tabs; | |
} | |
# Rails error pages | |
error_page 500 502 503 504 /500.html; | |
location = /500.html { | |
root /path/to/app/current/public; | |
} | |
# if assets are precompiled, and you want nginx to serve them | |
# directly | |
location ~ ^/(_assets)/ { | |
root /home/deploy/Projects/Vitrue/tabs/public; | |
expires max; | |
add_header Cache-Control public; | |
} | |
# location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { | |
# expires 1y; | |
# } | |
} | |
server { | |
listen 443; | |
client_max_body_size 4G; | |
server_name tabs.joelam.dev; | |
# ~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; | |
# path to static files | |
root /Users/joelam/Products/tabs/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; | |
access_log /Users/joelam/Products/tabs/log/access.log; | |
error_log /Users/joelam/Products/tabs/log/error.log; | |
# https settings | |
ssl on; | |
ssl_certificate /usr/local/etc/nginx/conf/tabs.crt; | |
ssl_certificate_key /usr/local/etc/nginx/conf/tabs.key; | |
location / { | |
# 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; | |
# 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; | |
# 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://tabs; | |
} | |
# Rails error pages | |
error_page 500 502 503 504 /500.html; | |
location = /500.html { | |
root /path/to/app/current/public; | |
} | |
location ~ ^/(_assets)/ { | |
root /home/deploy/Projects/Vitrue/tabs/public; | |
expires max; | |
add_header Cache-Control public; | |
} | |
# location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { | |
# expires 1y; | |
# } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment