【问题标题】:Spring Boot with embedded Tomcat behind Apache SSL proxy在 Apache SSL 代理后面嵌入 Tomcat 的 Spring Boot
【发布时间】:2022-01-19 14:41:35
【问题描述】:

我正在寻找一种能够在 Apache SSL 代理之后运行 Spring 应用程序的解决方案。我尝试了很多配置都没有成功。所有 Spring 响应都转到 http,导致 Not Found 错误。

以下是apache配置:

         SetEnv proxy-initial-not-pooled 1
         ProxyPreserveHost On
         KeepAlive On
         SSLProxyVerify none
         SSLProxyCheckPeerCN off
         SSLProxyCheckPeerName off
         SSLProxyCheckPeerExpire off
         ServerName server.mydomain.dom
         ProxyTimeout 600
         ProxyPass  /excluded !
        RequestHeader set X-Forwarded-Proto https
        RequestHeader set X-Forwarded-Port 443

         ProxyPass / http://127.0.0.1:8081/
         ProxyPassReverse / http://127.0.0.1:8081/

这些是 Spring 选项:

server.port=8081
server.forward-headers-strategy=NATIVE
#server.tomcat.redirect-context-root=false
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
server.tomcat.internal-proxies=.*

我在 Apache Tomcat/9.0.54 上使用 Spring Boot 2.5.6。 OS Apache 是在 Debian 9.13 上运行的 2.4.25 版本。

问题似乎是在登录应用程序并注销后发生的。如果我在登录操作后将 http 替换为 https,则可以导航到应用程序。在我注销之前,所有链接都可以正常工作。当我注销时,应用程序再次转到 http。

【问题讨论】:

    标签: spring spring-boot tomcat


    【解决方案1】:

    我解决了这个问题。第一步是添加

    server.tomcat.use-relative-redirects=true
    

    application.properties 中。使用此指令,代理可以正常工作。

    最后,我将 apache/应用程序配置为使用 AJP。

    【讨论】:

      猜你喜欢
      • 2014-10-16
      • 2018-02-22
      • 2020-04-06
      • 2021-03-03
      • 1970-01-01
      • 2019-11-27
      • 2013-08-25
      • 2017-01-15
      • 2018-05-28
      相关资源
      最近更新 更多