nginx+Unicornでサブディレクトリでアプリを動かす


PassengerUnicorn

nginx


nginxroot
Ralispublic
cd /var/www/root
ln -s /var/www/my-app/current/public my-app

Capistrano使current
nginx

nginxupstreamserver
upstream unicorn-of-my-app {
  server www.example.com:8080;
}

server {
  listen 80;
  server_name www.exemple.com
  root /var/www/root;

  error_log /var/www/my-app/current/log/error.log;

  location /my-app {
    try_files $uri $uri.html $uri/index.html @unicorn-of-my-app;
  }

  location @unicorn-of-my-app {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_pass http://unicorn-of-my-app;
  }
}

location /my-app nginxtry_files
unicorn-of-my-app

config.ru



Unicorn/my-app
if
if ENV['RAILS_RELATIVE_URL_ROOT']
  map ENV['RAILS_RELATIVE_URL_ROOT'] do
    run MyApp::Application
  end
else
  run MyApp::Application
end

config.ru
config.ruUnicorn

config.ruconfig.ru使


Unicorn

bundle exec unicorn_rails -E production -D --path /my-app

pathconfig.ru使ENV[RAILS_RELATIVE_URL_ROOT]

Rails



sub directorysub uri

config.action_controller.relative_url_root使Deprecated

config.runginxrewritelink_tourl_for

nginx+Passenger使