我有一个反向代理,Nginx在端口5000上运行,我希望将所有到端口5000的请求重定向为https请求。Nginx反向代理:将所有HTTP请求重定向到https
现在我得到的错误:400错误请求的普通HTTP请求发送到HTTPS端口
server {
listen 5000 ssl;
server_name myserver.com;
location/{
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host:5000;
add_header 'Access-Control-Allow-Methods' 'GET, POST';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
add_header 'Access-Control-Allow-Credentials' 'true';
# here comes the basic auth, after the options part
auth_basic 'Restricted';
auth_basic_user_file path/to/.htpasswd;
}
ssl on;
ssl_certificate path/to/crt;
ssl_certificate_key path/to/key;
}
嗯,我试图用增加
if ($scheme != "https") {
rewrite^https://$host$request_uri permanent;
}
if ($scheme != "https") {
return 301 https://$host$request_uri permanent;
}
似乎没有任何解决问题。我应该怎么做才能解决这个问题?
的可能的复制[nginx的重定向HTTPS到HTTP](https://stackoverflow.com/questions/3470290/nginx- redirect-https-http) – lifeisfoo