我有一个常规实例,当不在负载均衡器后面时工作正常.
我设置了一个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;
}
}
}
最佳答案
原文链接:https://www.f2er.com/nginx/435497.html