我们有一个 Spring Boot (Spring MVC) 应用程序,在 Apache SSL 代理后面的专用应用程序服务器上嵌入了 Tomcat。
代理服务器上的 SSL 端口是 4433,转发到应用程序服务器上的端口 8080。
所以代理服务器的 URL 转发如下:
https://proxyserver:4433/appname >>forward>> http://appserver:8080/
当没有代理运行时,首先发生的事情是
Spring Security 重定向请求,例如:
http://appserver:8080/ >>redirect>> http://appserver:8080/login
显示登录表单,通过扩展WebSecurityConfigurerAdapter
with
...
httpSecurity.formLogin().loginPage("/login") ...
...
没有代理它工作正常,但使用代理时需要更改重定向,
所以 Spring 应该重定向到相应的代理 URL,例如:
http://appserver:8080/ >>redirect>> https://proxyserver:4433/appname/login
但还没有成功。
我正在尝试应用这个解决方案:59.8 在前端代理服务器后面使用 Tomcat https://docs.spring.io/spring-boot/docs/1.1.1.RELEASE/reference/html/howto-embedded-servlet-containers.html#howto-use-tomcat-behind-a-proxy-server
我们已经配置了模组代理 https://en.wikipedia.org/wiki/Mod_proxy在 Apache 中,并验证它发送了预期的标头:
X-Forwarded-For: xxx.xxx.xxx.xxx
X-Forwarded-Host: proxyserver
X-Forwarded-Port: 4433
X-Forwarded-Proto: https
应用程序以参数启动:
export ARG1='-Dserver.tomcat.protocol-header=x-forwarded-proto'
export ARG2='-Dserver.tomcat.remote-ip-header=x-forwarded-for'
java $ARG1 $ARG2 -jar webapp.jar
重定向仍然不起作用。
它将继续在本地重定向到http://appserver:8080/login
这是客户无法获得的。
为了让这个场景发挥作用,我们还需要做些什么吗?
UPDATE
另外,我还担心代理 URL 中的“/appname”部分。在应用程序服务器上,应用程序的根目录为“/”。当通过代理时,应该如何指示 Spring 将“/appname”包含在发送回客户端的所有 URL 中?