无法配置apache服务器以代理SSL连接

时间:2013-08-07 15:22:21

标签: ssl apache2 virtualhost mod-proxy mod-ssl

我正在运行带有Apache Portable Runtime的Tomcat7上的应用程序,我买了一个SSL证书并正确配置它 - 当我尝试通过ip:端口组合连接时,它连接正常但警告我证书发给了域名,而不是IP。

我所使用的VPS没有SELinux(并且存在安装问题),这是AFAIK要求在apache中配置SSL所需的,所以我想将请求路由到Tomcat,它在它上面执行它端。

我将apache配置为代理连接,首先是端口80完美运行:

NameVirtualHost www.mysite.com:80
<VirtualHost www.mysite.com:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName http://www.mysite.com
ServerAlias http://www.mysite.com
ProxyPass / http://localhost:8180/MYSITE/
ProxyPassReverse / http://localhost:8180/MYSITE/
ProxyPassReverseCookiePath /MYSITE/ /
</VirtualHost>

然后使用SSL端口,由于某种原因不希望工作:

NameVirtualHost www.mysite.com:443
<VirtualHost www.mysite.com:443>
        SSLProxyEngine On
        ProxyPreserveHost On
        ProxyRequests Off
        ServerName https://www.mysite.com
        ServerAlias https://www.mysite.com
        ProxyPass / https://localhost:8443/MYSITE/
        ProxyPassReverse / https://localhost:8443/MYSITE/
        ProxyPassReverseCookiePath /MYSITE/ /
        CacheDisable *
</VirtualHost>

修改: 我添加了

RequestHeader set Front-End-Https "On"

指向VirtualHost www.mysite.com:443,根据:http://www.gossamer-threads.com/lists/apache/users/396577

这是在Tomcat的server.xml中配置的Tomcat APR连接器 -

<Connector port="8443" maxHttpHeaderSize="16500"
                 maxThreads="150"
                 enableLookups="false" disableUploadTimeout="true"
                 acceptCount="100" scheme="https" secure="true"
                 SSLEnabled="true"
                 SSLCertificateFile="x509-cert-path"
                 SSLCertificateKeyFile="key-file-path"
 />

没有错误/警告启用虚拟主机并重新启动Apache。当我尝试https时,这就是我在FFox中​​看到的:

SSL received a record that exceeded the maximum permissible length.

(Error code: ssl_error_rx_record_too_long)

在Chromium中:

Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.

Apache的error.log显示此警告消息:

[warn] [client 216.58.38.90] proxy: no HTTP 0.9 request (with no host line) on incoming request and preserve host set forcing hostname to be www.mysite.com for uri /

我花了好几天尝试配置它,如果有人解释了正在发生的事情以及如何解决它,我将非常感激。

非常感谢。 胜者。

1 个答案:

答案 0 :(得分:7)

您不需要Tomcat中的8443 HTTPS连接器。 Apache HTTPD应终止SSL连接,并通过ProxyPass / http://localhost:8080/MYSITE/.向Tomcat说纯文本。您只需要一个带有port=8080address=127.0.0.1的明文HTTP连接器,这样外人就无法获得它。

更好的是,不要在Tomcat中使用任何HTTP连接器,只需要一个AJP连接器,address=127.0.0.1,并在Apache中使用mod_proxy_ajp。

相关问题