4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

メモ。
アプリケーションサンプルは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;
    }
}
4
3
1

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
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?