Skip to content

Instantly share code, notes, and snippets.

@ctcherry
Created March 21, 2013 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctcherry/21453be0610ded1cfc36 to your computer and use it in GitHub Desktop.
Save ctcherry/21453be0610ded1cfc36 to your computer and use it in GitHub Desktop.
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 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment