我有一個反向代理,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