nginx反向代理tomcat 时,出现https redirect后变成http的问题解决方法

lishengyu 522 0

nginx反向代理tomcat 时,出现https redirect后变成http的问题解决方法

需要修改两个配置

1、nginx配置

 

1
2
3
4
5
6
7
8
9
10
location / {
    proxy_pass http://test-server;
    proxy_set_header Host $host;
    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;
}

 

2、修改tomcat下的conf/server/xml,在server.xml的Engine模块下面配置中上的Valve

 

1
2
3
4
<Valve  className="org.apache.catalina.valves.RemoteIpValve"
        remoteIpHeader="X-Forwarded-For"
        protocolHeader="X-Forwarded-Proto"
        protocolHeaderHttpsValue="https"/>

最后重启服务即可,https和http从重定向就不会串台了。

注:在k8s中设置,需要设置ingress nginx 配置https,在nginx转发中改为proxy_pass https://xxxxxxxxx

发表评论 取消回复
表情 图片 链接 代码

分享