侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 448 篇文章
  • 累计创建 183 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

详解NGINX访问https跳转到http的解决方法

WinJay
2022-11-18 / 0 评论 / 0 点赞 / 81 阅读 / 2679 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。

详解NGINX访问https跳转到http的解决方法

详解NGINX访问https跳转到http的解决方法

(nginx https代理tomcat redirect问题)

情况说明:

  • nginx配置https,tomcat正常http接受nginx转发。
  • nginx 代理https后,(java代码redirect地址)应用redirect https变成http

情况类似:

  • 浏览器打开https://www.zzvips.com/aaa.html,然后跳转到http://www.zzvips.com/aaa.html
  • 网站架构:用户--https--->nginx代理---http---->tomcat/nginx+php
  • nginx代理发给后端的请求是http协议,后端程序跳转获取到的协议是http,返回一个redirect(http header中带Location:http://www.ttlsa.com/aaa.html),浏览器收到location,跳转到了location指定的地方。

解决方法

解决方法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的解决了~

image-20221110110528783

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.

image-20221110110345908

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区