详解NGINX访问https跳转到http的解决方法
详解NGINX访问https跳转到http的解决方法
(nginx https代理tomcat redirect问题)
情况说明:
- nginx配置https,tomcat正常http接受nginx转发。
- nginx 代理https后,(java代码redirect地址)应用redirect https变成http
情况类似:
解决方法
解决方法1:
- 在nginx代理中增加一个header,标志用户请求是http还是https,后端获取header决定跳转到http/https页面。这个方法需要修改nginx配置和程序,不推荐,但是可以解决问题。
解决方法2(推荐):
- nginx代理中配置proxy_redirect(使用proxy_redirect重定向url)
proxy_redirect http:// $scheme://;
- 以上指令会将后端响应header location内容中的http://替换成用户端协议https://。
- NGINX访问https跳转到http的解决了~

upstream Sonic {
server 10.17.0.23;
}
server {
listen 80;
server_name sonic.litsoft.com.cn;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443 ssl;
server_name sonic.litsoft.com.cn;
ssl_certificate conf.d/ssl/litsoft.pem;
ssl_certificate_key conf.d/ssl/litsoft.key;
include conf.d/000.basic.ssl;
location / {
proxy_pass http://Sonic;
index index.html index.htm;
proxy_redirect http:// $scheme://;
# proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 5s;
proxy_send_timeout 5s;
proxy_read_timeout 5s;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
include conf.d/000.basic.common;
}
说明:
- 使用proxy_redirect将location中的协议转换为请求nginx的协议
跨域2
This request has been blocked; the content must be served over HTTPS.

评论区