我有一个常规实例,当不在负载均衡器后面时工作正常.
我设置了一个ELB,其中80转发到80和443转发到443和粘性会话.
之后,我转到任何https页面时都会收到此错误.
The plain HTTP request was sent to HTTPS port
我处理在我的nginx配置中的某些页面上强制https的过程.
为了让这个工作,我需要做什么?我在下面输入我的nginx配置的准系统版本.
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,我已经给了它所有的证书信息.问题是尝试在单个实例或配置文件中再次处理它.
解决方案是从配置文件中删除所有SSL内容.
所以删除这三行修复了一切:
ssl on;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;