1
1

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 3 years have passed since last update.

ロードバランサ配下のサーバにhttpsリダイレクトするとループする問題を解決

Posted at

通常、http→httpsのリダイレクトはhtaccessなりapacheのconfなりでこう書く。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

しかしLB配下にサーバが居ると無限ループが発生する。
こんな感じだろうか(ちょっと自信ないけど)

LB(http)→サーバ(httpなのでリダイレクト→LBへ)→LB(http)→サーバ(httpなのでry

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !=https #←こいつ追記
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

これで解決。
おわり。

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?