问题描述:
springboot内部使用重定向redirect,https变成http
解决方案
1、nginx配置
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;
proxy_pass http://127.0.0.1:8080;
#proxy_redirect http:// https://;
2、Spring Boot 配置(在启动类里面配置)
@Bean
public EmbeddedServletContainerFactory servletContainer(){
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setUriEncoding(Charset.forName("UTF-8"));
RemoteIpValve value = new RemoteIpValve();
value.setRemoteIpHeader("X-Forwarded-For");
value.setProtocolHeader("X-Forwarded-Proto");
value.setProtocolHeaderHttpsValue("https");
factory.addEngineValves(value);
return factory;
}
3、若是war包,在tomcat的在server.xml的Engine模块下面配置多一个以下的Valve
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
原文链接:https://blog.csdn.net/baidu_33632012/java/article/details/100018716