使用Apache和Tomcat进行SSL卸载给无限循环| mod_proxy_ajp的

我正在使用以下configuration进行设置

负载平衡器 – > Apache Web服务器(2) – >在tomcat上部署的应用程序(通过集群pipe理5个节点)

在已部署的应用程序中,我们确实有一些需要使用HTTPS模式访问的安全部分,我们试图通过在负载平衡器级别安装SSL证书来使用SSL卸载。

这里是Apache服务器configurationListen 80

<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/ ServerName prod.mysite.com LogLevel warn ErrorLog logs/prod.mysite.com-error_log CustomLog logs/prod.mysite.com-access_log common Include conf/sf.conf </VirtualHost> 

sf.conf

 ProxyPass /favicon.ico ! ProxyErrorOverride On ProxyStatus On ProxyRequests Off ProxyBadHeader Ignore ProxyPass / balancer://cluster/ ProxyPassReverse / balancer://cluster/ <Proxy balancer://cluster> BalancerMember ajp://xxx.xx.xx.xx:48009 route=node1 keepalive=On ping=3 retry=3 BalancerMember ajp://xxx.xx.xx.xx:48009 route=node2 keepalive=On ping=3 retry=3 BalancerMember ajp://xxx.xx.xx.xx:48009 route=node3 keepalive=On ping=3 retry=3 ProxySet stickysession=JSESSIONID|jsessionid lbmethod=byrequests timeout=300 nofailover=On </Proxy> 

其余的configuration都是非常标准的Apacheconfiguration,在Load Balance上正确安装了SSL证书。

当我在HTTP模式下打开我的应用程序时,一切工作正常,但是当应用程序试图redirect到SSL模式(https页)时,我得到无限的redirect错误。

我检查了日志文件,看来底层的应用程序正在将客户端redirect到HTTPS模式,并且Apache Web服务器再次发送HTTP请求,导致无限的redirect。

我不知道我在做什么错误或哪部分进程configuration不正确。

任何人都可以帮助我了解根本原因

根本原因在于,在负载均衡器执行SSL的情况下,对站点安全部分的所有请求将以HTTP方式到达,即使客户端使用SSL也是如此。 SSL包装被负载平衡器删除,请求作为正常的HTTP请求到达Apache,并再次被redirect到SSL导致无限循环的redirect。

解决scheme是基于x-forwarded-proto头redirect,大多数负载平衡器添加请求来解决这个问题。

即。 如果x-forwarded-proto=httpredirect到HTTPS,或者x-forwarded-proto=https继续正常

请参阅https://stackoverflow.com/questions/26620670/apache-httpx-forwarded-proto-in-htaccess-is-causing-redirect-loop-in-dev-envir如何在您的网&#x7AD9;.htaccess文件中做到这一点,但一些谷歌search会在其他平台和语言上find方法。