secret
Created

nginx with unicorn on a subdirectory

  • Download Gist
gistfile1.txt
1 2 3 4 5 6
Unicorn conf can be your normal stuff, set it to the same port as "upstream app_unicorn"
 
The trick is now to start it with the env variable: RAILS_RELATIVE_URL_ROOT=/sub
So the full command I use is:
 
RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/sub bundle exec unicorn -c unicorn_config.rb -D
nginx.cont
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
upstream app_unicorn {
server 127.0.0.1:8001 fail_timeout=0;
}
 
server {
root /someapp/path/current/public;
 
# Handle assets and direct requests to the right place
location ~* /sub(/.*)? {
try_files $1/index.html $1.html $1 @app_proxy;
}
 
location @app_proxy {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_unicorn;
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.