2017-03-03 17 views
1

Amazon ELBの背後にあるEC2マシンでウェブサイトを実行しています。
私はELB上でSSLを設定しています。そのため、httpsだけでなくHTTPも処理しています。 https上のすべてのリクエストは完全に機能します。しかし、HTTPリクエストをhttpsに強制的に(リダイレクトする)必要があります。何らかの理由で、動作しません。nginxのhttpsリダイレクトへのアクセス

nginxでリダイレクトルールを追加しましたが、そのルールを有効にするたびに、nginxサーバーが応答を停止します。ここで

server { 
listen 80; 
server_name domain1.com; 
gzip on; 
gzip_proxied any; 
gzip_types text/plain text/xml text/css application/x-javascript; 
gzip_vary on; 

access_log /var/log/nginx/domain1.access.log; 

location/{ 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_pass http://127.0.0.1:4000/; 
    ### Redirect http to https #### 
    if ($http_x_forwarded_proto != "https") { 
    rewrite ^(.*)$ https://$server_name$1 permanent; 
    } 
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;"; 
} 
} 

は、ロードバランサの設定です: Amazon ELB Config

私は設定と間違っつもりどこに私を助けてください。 TIA。

+0

は、使用傾ける理由は、' 301 HTTPSを返すことがありますか? –

答えて

0

次のことを試してみてください。

server { 
    listen 80; 
    listen [::]:80; 
    server_name domain1.com; 
    return 301 https://$host$request_uri; 
} 
0

私はこのコードを提案します。私のVPS上TESTEはなく、アマゾンELB

server { 
server_name example.com www.example.com; 
     listen 80; 
     return 301 https://example.com$request_uri; 
} 
server { 
server_name example.com; 
     root /home/user/www/example/; 
     include global.conf; 
     include php.conf; 
     include ssl.conf; 
     ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; 
     ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; 

} 
server{ 
server_name www.example.com; 
     include ssl.conf; 
     return 301 https://example.com$request_uri; 
     ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
     ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; 
} 

ファイルのssl.confのcontaint:; `// $ホストの$ REQUEST_URIを:

listen 443 ssl http2; 
listen [::]:443 ssl http2; 

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
ssl_prefer_server_ciphers on; 
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AES$ 
ssl_session_timeout 1d; 
ssl_session_cache shared:SSL:50m; 
ssl_stapling on; 
ssl_stapling_verify on; 
add_header Strict-Transport-Security max-age=15768000; 
関連する問題