使用mod-proxy和SSL的Apache VirtualHost

我试图设置一个服务器与多个Web应用程序,这将通过Apache的VirtualHost(在同一台服务器上运行的Apache)服务。 我的主要限制是每个Web应用程序都必须使用SSLencryption。 在googlesearch了一会儿之后,在stackoverflow上查看其他问题,我为VirtualHost编写了以下configuration:

<VirtualHost 1.2.3.4:443> ServerName host.domain.org <Proxy *> Order deny,allow Allow from all </Proxy> SSLProxyEngine On ProxyRequests Off ProxyPreserveHost On ProxyPass / https://localhost:8443/ ProxyPassReverse / https://localhost:8443/ </VirtualHost> 

即使https://host.domain.org:8443可以访问,但是https://host.domain.org不是,这打破了我的虚拟主机configuration的目的。 Firefox抱怨说,即使成功连接到服务器,连接也被中断。 我也在apache error.log中得到以下警告:

 proxy: no HTTP 0.9 request (with no host line) on incoming request and preserve host set forcing hostname to be host.domain.org for uri 

在Web应用程序(Tomcat服务器)上,访问日志显示一个奇怪的访问请求:

 "?O^A^C / HTTP/1.1" 302 

以下是我直接连接到https://host.domain.org:8443时获得的正确访问权限:

 "GET / HTTP/1.1" 302 

最后,我还应该提到,当我不使用SSL时,虚拟主机工作得很好。

我怎样才能做这个工作?

谢谢

最后我find了一个办法让它工作。 首先,我尝试了戴夫切尼的build议,所以我安装了Apache服务器redirect到非SSL端口的其他证书(所以代理redirect到http:// localhost:8080 / )。 不幸的是,它并没有像networking浏览器那样完全工作,在连接后,https被立即转换为http。 所以我恢复到使用https:// localhost:8443 /和最后的接触,使其工作是再次添加SSLProxyEngine。

这是由此产生的VirtualHostconfiguration:

 <VirtualHost 1.2.3.4:443> ServerName host.domain.org <Proxy *> Order deny,allow Allow from all </Proxy> SSLEngine on SSLProxyEngine On SSLCertificateFile /etc/apache2/ssl/certificate.crt SSLCertificateKeyFile /etc/apache2/ssl/certificate.key ProxyRequests Off ProxyPreserveHost On ProxyPass / https://localhost:8443/ ProxyPassReverse / https://localhost:8443/ </VirtualHost> 

感谢大家的帮助:)

试试这个configuration

 <VirtualHost 1.2.3.4:443> ServerName host.domain.org SSLEngine On # include other ssl options, like cert and key here ProxyRequests Off ProxyPreserveHost On <Location /> ProxyPass http://localhost:8443/ </Location> </VirtualHost> 

如果您的应用程序需要访问来自代理连接的SSL信息,则应考虑使用mod_proxy_ajp和tomcat ajp1.3连接器。

那么,我不明白这里是为什么你需要从你的Apache到你的应用程序,似乎是在同一台机器( http:// localhost:8443 / )的SSL连接。

我想通常的方式来设置这样的事情是让Apache提供SSLencryption到“客户”端,如互联网,并有一个未encryption的连接到应用程序。 这也给你更多的自由来debugging你的应用程序响应。

Dave Cheney提到的另一件事是使用本地的tomcat连接器来实​​现负载平衡和其他function。

但是,如果您的目标是在同一台服务器上运行多个启用了SSL的Web应用程序。 在前面添加apache并不会使用你的上面的configuration来平衡它们,你仍然需要一个负载平衡器,或者你可以像下面这样使用apache的代理平衡器模块:

 ProxyRequests Off <Proxy balancer://someapplication> BalancerMember http://127.0.0.1:18443 keepalive=on max=2 retry=30 BalancerMember http://127.0.0.1:18444 keepalive=on max=2 retry=30 BalancerMember http://127.0.0.1:18445 keepalive=on max=2 retry=30 </Proxy> <VirtualHost 1.2.3.4:443> SSLEngine on SSLCipherSuite SSLv2:-LOW:-EXPORT:RC4+RSA SSLCertificateFile /path/to/cert.pem SSLCertificateKeyFile //path/to/key.pem SSLVerifyClient optional RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e <Location /> SetHandler balancer-manager Order allow,deny Allow from all </Location> ProxyPass / balancer://someapplication:443/ ProxyPassReverse / balancer://someapplication:443/ ProxyPreserveHost on 

你真的需要代理HTTPS服务吗? 你可能想代理localhost中的非SSL服务,例如

 ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ 

首先,我会看看,如果你能做一个从本地到localhost:8443的请求,看看是否成功(IE做一个GET或wget http:// localhost:8443 )

林不知道为什么你的虚拟主机侦听端口443然后代理到另一个SSL主机

为什么不能应用程序本身使用443? 如果你不能改变它,你可以使用iptables来redirect端口

检查您的SSL错误日志,并确保您无法validationCA证书链。