LoginSignup
3

More than 5 years have passed since last update.

posted at

rackアプリケーションをnginx+unicornで公開する時、redirect時にホスト名を保持できない

メモ。
アプリケーションサンプルはSinatra。

get '/' do
  redirect 'パス'
end

以下のnginxの設定の時、 http://example.com/ にアクセスした場合
http://unicorn/パス へ遷移しようとしページが表示されない。

upstream unicorn {
  server localhost:3000;
}
server {
    (中略)
    location / {
        proxy_pass http://unicorn;
    }
}

以下のヘッダを設定することで、正常に
http://example.com/パス へ遷移する。

upstream unicorn {
  server localhost:3000;
}
server {
    (中略)
    location / {
        proxy_pass http://unicorn;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
3