问题描述: 使用 https 访问 tomcat 部署的 war 内的静态资源,https 协议没有被正确的加上。 css/js/图片等资源都是变成了 http:// 协议了。

解决办法如下:

一、 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  $http_x_forwarded_proto;

proxy_redirect http:// $scheme://;

二、 tomcat 配置

编辑 conf/server.conf 文件:

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 添加下面这段 -->

        <Valve className="org.apache.catalina.valves.RemoteIpValve"
                remoteIpHeader="x-forwarded-for"
                remoteIpProxiesHeader="x-forwarded-by"
                protocolHeader="x-forwarded-proto" />

      </Host>
    </Engine>
  </Service>
</Server>