zoukankan      html  css  js  c++  java
  • Nginx SSL+tomcat集群,取不到https正确协议

    最近在做一个项目, 用到企业微信,架构上使用了 Nginx +tomcat 集群, 且nginx下配置了SSL,tomcat no SSL,项目使用https协议,但是在调试微信菜单的相关功能时却发现报错,报错信息如下:

    经过调试dofilter里面的代码,发现:
    浏览器中输入的URL是 https://shaidh.dhwrwi.com/dheu/syuu.do
    但是打断点调试request.getRequestURL() 输出来的 一直是  http://shaidh.dhwrwi.com/dheu/syuu.do

    查阅了一些资料,找到了解决方案:

    解决方法很简单,只需要分别配置一下 Nginx 和 Tomcat 就好了,而不用改程序。

    配置 Nginx 的转发选项:

    在nginx安装目录的 conf文件夹中找到vhost.conf,

    在 proxy_set_header       Host $host;  下面添加:

    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 

    proxy_set_header X-Forwarded-Proto $scheme;

    配置Tomcat server.xml 的 Engine 模块下配置一个 Valve:

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

    配置双方的 X-Forwarded-Proto 就是为了正确地识别实际用户发出的协议是 http 还是 https。

    此时再查看request.getRequestURL()就会发现输出的是https

  • 相关阅读:
    2001.3.9 每日总结
    2021.3.5
    2021.3.4每日总结
    2021.3.3每日总结
    每日总结2021.3.2
    2021.1.13
    2021.1.12
    PodPreset
    ingress-nginx安装
    RBAC
  • 原文地址:https://www.cnblogs.com/llfddmm/p/8074697.html
Copyright © 2011-2022 走看看