LoginSignup
15
16

More than 5 years have passed since last update.

[Nginx]AWSのELBでSSLを設定した場合のSSL判定

Last updated at Posted at 2015-01-05

ELBでSSLを設定するメリット

  • ELBにSSLを設定できる
  • インスタンスごとにSSLを設定する必要がない

注意点

ELBでSSLの設定をしてしまうと、nginx側には httpshttp も80番ポートで入ってきてしまう。

解決策

ELBにSSLを設定してポートフォワードした場合、環境変数に X-Forwarded-Proto がセットされるので下記のように使う。

server {
    listen 80;
    server_name example.jp;
    root /var/www/your_app/;


    if ($http_x_forwarded_proto = https) {
      rewrite ^ http://example.jp$request_uri? permanent;
    }


    proxy_connect_timeout 60;
    proxy_read_timeout    150;
    proxy_send_timeout    60;

    location / {

    }
  }
15
16
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
15
16