Create a gist now

Instantly share code, notes, and snippets.

@ctcherry /nginx.cont Secret
Created Mar 21, 2013

What would you like to do?
nginx with unicorn on a subdirectory
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
upstream app_unicorn {
server 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment