public
Last active

Nginx individual site config for multiple rails apps with Unicorn

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
##############################################################
# Upstream must have unique name and unique socket. #
# The socket must match what is in the app's unicorn.rb file #
##############################################################
upstream railsapp1_server {
server unix:/tmp/railsapp1.sock fail_timeout=0;
}
 
##############################
# Rewrite www to non-www #
##############################
server{
server_name www.railsapp1.com;
rewrite ^(.*) http://railsapp1.com$1 permanent;
}
 
##############################
# Server configs go here #
##############################
server {
listen 80;
 
client_max_body_size 4G;
server_name railsapp1.com;
keepalive_timeout 5;
 
#########################################################
# This should go to the public folder of your rails app #
#########################################################
root /var/www/railsapp1.com/current/public;
 
try_files $uri/index.html $uri.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
 
#############################################
# This should be http://upstream; with the #
# upstream specified above. #
#############################################
proxy_pass http://railsapp1_server;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
#########################################################
# This should go to the public folder of your rails app #
#########################################################
root /var/www/railsapp1.com/current/public;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.