Apache前面的Tomcat的SSL设置

即时通讯设法设置Apache与SSl和代理SSL请求到我的Tomcat实例。 我想我做了SSL的工作,但仍然是一个错误,显示:

Bad Gateway The proxy server received an invalid response from an upstream server. 

* SSL虚拟主机*

 LoadModule ssl_module modules/mod_ssl.so Listen 443 <VirtualHost _default_:443> SSLEngine On SSLProxyEngine On DocumentRoot "/var/apache-tomcat-7.0.34/webapps/Learn2Gether/" SSLCertificateFile /etc/pki/tls/learn2gether/cert-6090205098829887.pem SSLCertificateKeyFile /etc/pki/tls/learn2gether/private_key_unlocked.pem SSLCertificateChainFile /etc/pki/tls/learn2gether/rubca-chain.pem BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL ServerName www.learn2gether.rubel.rub.de ServerAlias learn2gether.rubel.rub.de #RewriteRule ^\/$ /Learn2Gether/index.html [PT] ##RewriteRule ^/(.*)$ /$1 [PT] ProxyRequests Off ProxyPreserveHost On ProxyPass / https://localhost:8443/ ProxyPassReverse / https://localhost:8443/ </VirtualHost> ~ 

HTTP VHredirect到HTTPS

 NameVirtualHost *:80 <VirtualHost _default_:80> ServerName www.learn2gether.rubel.rub.de ServerAlias learn2gether.rubel.ruhr-uni-bochum.de RewriteEngine on # DocumentRoot "/var/apache-tomcat-7.0.34/webapps/Learn2Gether/" RewriteCond %{HTTP_HOST} !^learn2gether.rubel.ruhr-uni-bochum\.de [NC] RewriteRule ^/(.*)$ http://learn2gether.rubel.ruhr-uni-bochum.de/$1 [R=301,L] RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://%{HTTP_HOST}$1 [L] #RewriteRule ^\/$ /Learn2Gether/index.html [PT] #RewriteRule ^/(.*)$ /$1 [PT] #ProxyPass / https://localhost:8443/ #ProxyPassReverse / https://localhost:8443/ </VirtualHost> 

雄猫apache连接器

  <Connector port="8443" protocol="HTTP/1.1" connectionTimeout="20000" compression="on" compressionMinSize="32" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,application/x-javascript,text/css" redirectPort="8443" URIEncoding="UTF-8" proxyPort="443" proxyName="learn2gether.rubel.ruhr-uni-bochum.de" scheme="https" secure="true" /> 

当代理http或https到https时,您需要将apacheconfiguration为ssl 客户端 。 当apache与Tomcat服务器交谈时,它终究作为Web客户端。 但是Apache通常不会像开箱即用的SSL客户端那样工作。

首先我build议你首先考虑一下你是否真的需要这个,为什么你这样做。 当Tomcat和Apache在同一台服务器上运行时,常见的做法是让Tomcat只提供普通的http(或ajp)并将ssl卸载到Apache服务器上。 通常不需要在Apache和Tomcat服务器之间有SSL。 在tomcat服务器上没有ssl会节省很多麻烦。

所有你需要做的就是例如在你的tomcat实例中的端口8080上定义一个HTTP连接器,并在你的apache SSL虚拟主机中redirect所有请求:

 <VirtualHost _default_:443> SSLEngine On SSLCertificateFile /etc/pki/tls/learn2gether/cert-6090205098829887.pem SSLCertificateKeyFile /etc/pki/tls/learn2gether/private_key_unlocked.pem SSLCertificateChainFile /etc/pki/tls/learn2gether/rubca-chain.pem BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL ServerName www.learn2gether.rubel.rub.de ServerAlias learn2gether.rubel.rub.de ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost> 

但是,如果你仍然决定你需要SSL代理,你将需要添加更多的变化。 Apache需要能够充当SSL客户端,以及SSL服务器。 当Apache使用https与另一台服务器通话时,它终究扮演了客户端的angular色。 这不是那么容易,而且你可以运行很多问题。 你将需要添加这个:

 # turn on SSL proxying. SSLProxyEngine On # to tell Apache where to find CA certificates to check server certificates with: # (You can choose yourself where you put these certificates) SSLProxyCACertificatePath /path/to/ca/certificates. 

然后在这个path中,您需要将CA证书用于签署您与之通信的服务器使用的证书。 如果您使用“自签名”证书,则需要将其放在此目录中。

一旦你完成了,你需要在该目录中运行“c_rehash”。 c_rehash是标准openssl发行版的一部分。 c_rehash在此目录中创build散列别名。 Apache需要这些。

为了testing一切是否存在,您可以执行以下操作:

  openssl s_client -CApath /path/to/ca/certificates -connect remoteserver:8443 

如果连接成功,你会得到一个提示,你可以input一个请求。 只是尝试一些。

  GET / 

看看你有什么东西 如果这个testing是成功的,Apache也应该工作。

您现在可以添加ReWriteRule或Proxy语句以将连接转发到您的https服务器。