我有一个反向代理,Nginx 在端口 5000 上运行,我想将所有进入端口 5000 的请求作为 https 请求重定向。
现在我收到错误:400 Bad Request The plain HTTP request was sent to HTTPS port
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;
}
似乎没有什么能解决问题。我应该怎么做才能解决这个问题?