2017-08-21 6 views
0

を働いていないリダイレクト設定:私は「 ...Elastic Beanstalkでのnginxの私は、httpをhttpsにリダイレクトしようとしていると私は、この設定を持っている

files: 
    "/etc/nginx/conf.d/robots.conf": 
     mode: "000544" 
     owner: root 
     group: root 
     content: | 
      server { 
       listen 80; 

       server_name example.com; 

       location =/health { 
        return 200 "health-check"; 
       } 

       location/{ 
        if ($http_x_forwarded_proto != "https") { 
         return 301 https://$host$request_uri; 
        } 
       } 
      } 
      server { 
       listen 80 default_server; 

       server_name www.example.com; 

       location =/health { 
        return 200 "health-check"; 
       } 

       location/{ 
        if ($http_x_forwarded_proto != "https") { 
         return 301 https://$host$request_uri; 
        } 
       } 
      } 

しかし、私はhttp://example.comまたはhttp://www.example.comに行くとき何のリダイレクトはありません複数の設定を試しましたが、決して完全に機能しないようです。

答えて

0

これを行うための最善の方法は、

server { 
     listen   80; 
     server_name my.example.com; 
     return   301 https://$server_name$request_uri; 
} 

server { 
     listen   443 ssl; 
     server_name my.example.com; 
     # add Strict-Transport-Security to prevent man in the middle attacks 
     add_header Strict-Transport-Security "max-age=31536000"; 

     [....] 
} 
+0

はそれを試み、以下のようにあなたの設定を設定して、それが仕事をdoesntの。 config isntが実装されたようです... – Ferus

+1

'service nginx reload'で設定をリロードしましたか? –

+0

いいえ、私はちょうど 'eb deploy'を使ってコミットしてデプロイしています。どこに' service nginx reload'を置くのですか?それとも、私はインスタンスにsshして、それを行う必要がありますか? – Ferus

関連する問題