jch*_*ysk 5 ssl nginx https amazon-elb
我有一个常规实例,当不在负载平衡器后面时它可以正常工作。我设置了一个 ELB,80 转发到 80,443 转发到 443 和粘性会话。之后,我在访问任何 https 页面时收到此错误。
The plain HTTP request was sent to HTTPS port
Run Code Online (Sandbox Code Playgroud)
我处理在我的 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
最终在 nginx IRC 频道中从 vandemar 那里得到了答案。看起来很简单,但我很难弄清楚。ELB 正在处理 SSL,我已经向它提供了所有证书信息。问题在于尝试在各个实例或配置文件中再次处理它。解决方案是从配置文件中删除所有 SSL 内容。所以删除这三行就解决了一切:
ssl on;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
Run Code Online (Sandbox Code Playgroud)