Tomcat Spring安全和AJP代理

Tomcat Spring安全和AJP代理,tomcat,spring-security,mod-proxy,ajp,Tomcat,Spring Security,Mod Proxy,Ajp,我将Spring安全性和Apache代理用于web应用程序。使用标准mod_代理时,一切正常,但切换到AJP代理后,Spring安全重定向出现问题 Apache配置: <VirtualHost *:80> ServerName domain.com ProxyPass / ajp://localhost:8009/Context/ ProxyPassReverse / ajp://localhost:8009/Context/ </VirtualHost>

我将Spring安全性和Apache代理用于web应用程序。使用标准mod_代理时,一切正常,但切换到AJP代理后,Spring安全重定向出现问题

Apache配置:

<VirtualHost *:80>
  ServerName domain.com

  ProxyPass / ajp://localhost:8009/Context/
  ProxyPassReverse / ajp://localhost:8009/Context/
</VirtualHost>

ServerName域名.com
ProxyPass/ajp://localhost:8009/Context/
ProxyPassReverse/ajp://localhost:8009/Context/
当我打电话时,我看到一个登录表单

当我提交表格时,我会去验证

然后Spring Security应该重定向到,但它会重定向到

我怎样才能摆脱上下文路径?为什么Spring Security到处都添加了它

Spring Security网站上也有类似的问题,但没有人回答:

附言。 奇怪的是,谷歌没有找到与这个问题更相关的东西。我是唯一一个使用Spring Security+AJP的人吗?也许这是一个错误的模式

解决方案:

<VirtualHost *:80>
  ServerName domain.com

  RewriteEngine on
  RewriteRule ^/Context/(.*)$ /$1 [R=301]

  ProxyPass / ajp://localhost:8009/Context/
  ProxyPassReverse / ajp://localhost:8009/Context/
</VirtualHost>

ServerName域名.com
重新启动发动机
重写规则^/Context/(.*)$/$1[R=301]
ProxyPass/ajp://localhost:8009/Context/
ProxyPassReverse/ajp://localhost:8009/Context/

Spring Security是web应用程序上下文感知的,这意味着它的重定向将始终基于当前web应用程序上下文。这是出于设计考虑,因为您的应用程序服务器可能运行多个不同的web应用程序,这些应用程序不应相互干扰

您是否只在服务器上运行此应用程序,并且可以将其作为根应用程序部署在Tomcat上(例如,将其放入
webapps/ROOT/
)?这将消除您的上下文前缀并解决您的问题


另一个选项可能是在将重定向URL传递给客户端之前在应用服务器上重写重定向URL,例如。G使用(如mod_rewrite,但适用于JavaEEWeb应用程序)。当然,您必须在
web.xml
中注意适当的过滤器顺序,因为Spring Security也使用过滤器作为其逻辑。

谢谢!最后我用Apache mod_rewrite结束了我的工作。请参阅有关我的问题的更新。