Spring 在 Apache SSL 代理后面嵌入 Tomcat 启动
Spring Boot with embedded Tomcat behind Apache SSL proxy
我正在寻找能够 运行 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 上 运行ning 的 2.4.25 版本。
问题似乎发生在登录应用程序并注销后。如果我在登录操作后将 http 替换为 https,我就可以导航到应用程序中。在我注销之前,所有链接都可以正常工作。当我注销时,应用程序再次转到 http.
我解决了问题。第一步是添加
server.tomcat.use-relative-redirects=true
在application.properties。使用此指令,代理可以正常工作。
最后,我将 apache/application 配置为使用 AJP。
我正在寻找能够 运行 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 上 运行ning 的 2.4.25 版本。
问题似乎发生在登录应用程序并注销后。如果我在登录操作后将 http 替换为 https,我就可以导航到应用程序中。在我注销之前,所有链接都可以正常工作。当我注销时,应用程序再次转到 http.
我解决了问题。第一步是添加
server.tomcat.use-relative-redirects=true
在application.properties。使用此指令,代理可以正常工作。
最后,我将 apache/application 配置为使用 AJP。