设置Elastic Load Balancer后,我的https不再工作。 Nginx错误

我有一个正常的实例,当不在负载均衡器后面时可以正常工作。 我build立了一个ELB,80转发到80和443转发到443和粘性会话。 之后,我收到此错误时去任何https页面。

The plain HTTP request was sent to HTTPS port 

我处理在我的nginxconfiguration中的某些页面上强制https的过程。 我需要做些什么才能做到这一点? 我在下面放置一个我的nginxconfiguration的准系统版本。

 http { include mime.types; default_type application/octet-stream; # Directories client_body_temp_path tmp/client_body/ 2 2; fastcgi_temp_path tmp/fastcgi/; proxy_temp_path tmp/proxy/; uwsgi_temp_path tmp/uwsgi/; server { listen 443; ssl on; ssl_certificate ssl.crt; ssl_certificate_key ssl.key; server_name www.shirtsby.me; if ($host ~* ^www\.(.*)) { set $host_without_www $1; rewrite ^/(.*) $scheme://$host_without_www/$1 permanent; } location ~ ^/(images|img|thumbs|js|css)/ { root /app/public; } if ($uri ~ ^/(images|img|thumbs|js|css)/) { set $ssltoggle 1; } if ($uri ~ "/nonsecure") { set $ssltoggle 1; } if ($ssltoggle != 1) { rewrite ^(.*)$ http://$server_name$1 permanent; } location / { uwsgi_pass unix:/site/sock/uwsgi.sock; include uwsgi_params; } } server { listen 80; server_name www.shirtsby.me; if ($host ~* ^www\.(.*)) { set $host_without_www $1; rewrite ^/(.*) $scheme://$host_without_www/$1 permanent; } if ($uri ~ "/secure") { set $ssltoggle 1; } if ($ssltoggle = 1) { rewrite ^(.*)$ https://$server_name$1 permanent; } location ~ ^/(images|img|thumbs|js|css)/ { root /app/public; } location / { uwsgi_pass unix:/home/ubuntu/site/sock/uwsgi.sock; include uwsgi_params; } } } 

最终从nginx IRC频道获得vandemar的回答。 看起来很简单,但我拼命找出答案。 ELB正在处理SSL,我已经给了它所有的证书信息。 问题是试图再次在个别实例或configuration文件中处理它。 解决的办法是从configuration文件中删除所有的SSL东西。 所以删除这三条线固定了一切:

 ssl on; ssl_certificate ssl.crt; ssl_certificate_key ssl.key; 

我遇到过同样的问题。 但后来我注意到我的elb-listenerconfiguration不正确。 我设置了负载平衡器协议:https,负载平衡器端口:443,实例端口:443,但忘记将实例协议从http更改为https。