Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
圣杯&x2B;Tomcat+;切换到HTTPS时发生Apache错误_Apache_Tomcat_Grails_Ajp - Fatal编程技术网

圣杯&x2B;Tomcat+;切换到HTTPS时发生Apache错误

圣杯&x2B;Tomcat+;切换到HTTPS时发生Apache错误,apache,tomcat,grails,ajp,Apache,Tomcat,Grails,Ajp,我们有一个GrailsWeb应用程序,运行在Apache2后面的tomcat7中。通过将ProxyPass与ajp协议一起使用,一切正常: ProxyPass / ajp://localhost:9013/ ProxyPassreverse / ajp://localhost:9013/ 其中9013是tomcat的server.xml中的AJP端口 现在,我们的问题是这个。我们的Grails应用程序同时运行HTTP和HTTPS。当您访问应用程序中的某个区域时,Spring

我们有一个GrailsWeb应用程序,运行在Apache2后面的tomcat7中。通过将ProxyPass与ajp协议一起使用,一切正常:

ProxyPass         / ajp://localhost:9013/
ProxyPassreverse  / ajp://localhost:9013/
其中9013是tomcat的
server.xml
中的AJP端口

现在,我们的问题是这个。我们的Grails应用程序同时运行HTTP和HTTPS。当您访问应用程序中的某个区域时,Spring Security(Grails Spring Security核心插件)会使用HTTP将您从地址重定向到HTTPS,例如,当您点击:

Spring Security会将您重定向到:

但是现在,当它重定向到那里时,服务器挂起,最后Firefox给出“Firefox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求”错误

我是否正确地假设AJP代理的某些重定向正在恶化?是否有人可以提供有关此设置如何工作的更多信息


进一步研究后,我们发现:

当直接(通过IP和端口)访问tomcat中的应用程序时,一切都能100%正常工作。但是一旦我们通过Apache,Spring安全重定向就无法工作。您在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。
感谢您,我不确定spring security core在切换到HTTPS时如何决定使用哪个端口,但是默认的Tomcat配置为AJP连接器的redirectPort=“8443”,也许您需要更改为443,以便重定向将命中Apache的HTTPS端口。

免责声明,我不是Grails方面的专家

但根据您的描述,配置可能如下所示:

SSL被卸载到apachehttpd。因此,只有ajp连接器需要在Tomcat中配置,或者可能需要额外的http连接器,仅用于测试目的。 通过以下方式为ApacheHTTPD配置启用SSL 及


重定向永久/安全/路径https://www.example.com/secure/path
ProxyPass/ajp://localhost:8009/
ProxyPassreverse/ajp://localhost:8009/
#SSL配置
...
ProxyPass/ajp://localhost:8009/
ProxyPassreverse/ajp://localhost:8009/
应该有用

另一个好处是,当SSL卸载到ApacheHTTPD时,您可能会看到性能改进

此外,为什么不对所有内容强制使用SSL:

<VirtualHost _default_:80>
RedirectPermanent / https://www.example.com/
</VirtualHost>

<VirtualHost _default_:443>

# SSL config
    ...

ProxyPass         / ajp://localhost:8009/
ProxyPassreverse  / ajp://localhost:8009/
</VirtualHost>

重定向永久/https://www.example.com/
#SSL配置
...
ProxyPass/ajp://localhost:8009/
ProxyPassreverse/ajp://localhost:8009/
至于为什么会有无限循环,可能与Spring Security的sendRedirect有关。
如果您可以发布完整的apache VirtualHost和tomcat ajp连接器配置,可能会给我们提供更多线索。

Grails/Spring安全性具有以下属性:

grails {
   // redirect ports
   plugins {
      springsecurity {
         portMapper {
            httpPort = 80
            httpsPort = 443
         }
      }
   }
}

您可以使用hongo提供的上述httpd配置(端口80/443,SSL终止于Apache)来实现这一点。您可能还需要适当地设置
server.url
属性。

虽然我还不能告诉您如何解决它,但我可以告诉您问题出在哪里

它本质上与重写入口点有关

因此,在这些情况下,你应该做的一部分是:

grails.plugins.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
然后,通过设置标头来查看我们是否真正使用http/https,默认值为:

RequestHeader集合X-Forwarded-Proto“http”

现在我在nginx中可以很好地工作了。在前面使用apache的情况下,问题在于重写规则没有占用apache服务器。他们只不过是找回了自我。因此,当它运行时,它基本上会遇到无限重定向,因为它只知道您所在的9013服务器


现在我想我只需要编写我自己的定制HttpsEntry,但我想有一些apache设置可以让它正常工作。

顺便说一句。。。这是你的答案

因此,请执行端口映射器设置,并像我前面所说的那样使用通道安全性

通道安全性需要知道何时转发到http/https

但是在重定向中,您需要保留代理设置,以便request.getServerPort()可以找到它们。您可以将其添加到Apache httpd.conf中:


ProxyPreserveHost On

这将不起作用,因为我们需要运行多个tomcat实例,所以一旦我们有两个都需要https的应用程序,其中一个将无法运行,因为它无法绑定到端口443。这里不涉及绑定,它只是Tomcat重定向到HTTPS时将使用的端口的一个属性。但如上所述,我不确定spring security core是否使用此属性。它是否仅在重定向时失败,还是在尝试直接转到HTTPS页面时也失败?
grails.plugins.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true