问题:访问https但界面的js或css会加载http,获取不到https
解决方案
1、nginx配置
proxy_set_header Host $host; 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;
|
2、Spring Boot 配置(在启动类里面配置,此方法为Spring Boot 2.X以上)
@Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); 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"/>
|