我们有一个 Grails Web 应用程序,在 Apache2 后面的 tomcat7 中运行。通过使用 ProxyPass 和 ajp 协议(protocol),一切正常:
ProxyPass / ajp://localhost:9013/
ProxyPassreverse / ajp://localhost:9013/
其中 9013 是 Tomcat 的 server.xml
中的 AJP 端口。
现在,我们的问题是这样的。我们的 Grails 应用程序同时运行 HTTP 和 HTTPS。当转到应用程序中的某个区域时,Spring Security(Grails Spring Security 核心插件)会将您从使用 HTTP 的地址重定向到 HTTPS,例如当点击:
http://www.example.com/secure/path
Spring Security 会将您重定向到:
https://www.example.com/secure/path
但是现在,当它重定向到那里时,服务器挂起,最后 Firefox 给出“Firefox 已检测到服务器正在以永远不会完成的方式重定向对此地址的请求。” 错误.
我是否正确地假设 AJP 代理的某些重定向会出现问题?谁能提供有关此设置如何工作的更多信息?
进一步观察,我们发现了以下内容:
当直接(通过 IP 和端口)访问 tomcat 中的应用程序时,一切正常 100%。但是一旦我们通过 Apache,Spring Security 重定向就不起作用了。您不断在 Apache 日志中收到以下内容:
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:41 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
staging.server.com:80 41.133.194.248 - - [05/Apr/2012:14:03:42 +0200] "GET /user/signup HTTP/1.1" 302 223 "http://staging.server.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"
...
apache 似乎神奇地让它再次尝试 http,而不是重定向到 https。 谢谢
最佳答案
虽然我还不能告诉你如何解决它,但我可以告诉你问题是什么。
它本质上是重写入口点。
因此,在这些情况下你应该做的部分事情已经确定:
grails.plugins.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
然后,这将通过设置 header (默认为:)来查找我们是否真正位于 http/https 上:
RequestHeader 设置 X-Forwarded-Proto“http”
现在我在 nginx 中工作得很好。对于前面的 apache,问题是重写规则没有选择 apache 服务器。他们只是拾起 self 。因此,当它运行时,它基本上会遇到无限重定向,因为它只知道您所在的 9013 服务器。
现在我想我只需要编写自己的自定义 HttpsEntry,但我想有一些 apache 设置可以使这项工作正常进行。
关于apache - Grails + Tomcat + Apache 切换到 HTTPS 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10027056/