【问题标题】:Apache not Proxying HTTPS requests to TomCat, Just showing local index.htmlApache 没有向 TomCat 代理 HTTPS 请求,只显示本地 index.html
【发布时间】:2015-10-12 06:42:23
【问题描述】:

Centos 7、Apache 2.4、TomCat 7.0.52、Java 1.7

我正在尝试将 Apache 配置为使用 HTTPS 代理 tomcat 服务器(运行 Jira / Confluence):

(HTTPS:443) -> ApacheServer -> (HTTP:8090 或 HTTPS:8091) TomCat

目前 HTTP 代理工作完美,但我想让 HTTPS 工作。我不介意 Apache 和 Tomcat 之间的连接是否是 SSL(在同一台服务器上)。

当我访问 https://confluence.company.co.uk/ 时,我得到的是 /var/www/html/index.html 而不是代理。

这是来自 tomcat 的 Server.xml:

<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
           maxThreads="200" minSpareThreads="10"
           enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" />

<Connector port="8091" proxyPort="443" proxyName="confluence.company.co.uk"   acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false"
           maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" protocol="HTTP/1.1"
           redirectPort="8443" useBodyEncodingForURI="true" scheme="https" secure="true" />

从 Apache 的默认 /etc/httpd/conf.d/ssl.conf 更改的行:

ServerName confluence.company.co.uk:443
SSLCertificateFile /etc/pki/tls/certs/company.pem
SSLCertificateKeyFile /etc/pki/tls/private/company.key

Apache VHost 配置(在 /etc/httpd/conf.d/proxy_vhost.conf 中):

<VirtualHost *:80>
    ServerName  confluence.company.co.uk
    ProxyRequests Off
    <Proxy *>
    Order deny,allow
    Deny from all
    Allow from all
    </Proxy>
    <Location />
            AuthType Basic
            AuthName "Proxy Auth"
            AuthUserFile /var/www/company-auth/CONFLUENCE/.htpasswd
            Require user ukuser
            Satisfy any
            Deny from all
            Allow from 192.168.0.0/21
    </Location>
    ProxyPreserveHost On
    ProxyPass / http://confluence.company.co.uk:8090/
    ProxyPassReverse / http://confluence.company.co.uk:8090/
</VirtualHost>
<VirtualHost *:443>
    SSLProxyEngine On
    ProxyRequests Off
    <Proxy *>
    Order deny,allow
    Deny from all
    Allow from all
    </Proxy>
    ProxyPreserveHost On
    ProxyPass / https://confluence.company.co.uk:8091/
    ProxyPassReverse / https://confluence.company.co.uk:8091/
</VirtualHost>

更新

httpd.conf:http://pastebin.com/4bzwKLac ssl.conf:http://pastebin.com/M5FpJTMz

当我在 HTTPS 虚拟主机中包含 ServerName 时,httpd 无法启动,并且出现以下错误:

systemctl status httpd
   httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: failed (Result: exit-code) since Wed 2015-07-22 13:00:22 BST; 7s ago
   Process: 25953 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
   Process: 15243 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
   Process: 25951 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
   Main PID: 25951 (code=exited, status=1/FAILURE)

   Jul 22 13:00:21 confluence.syzygy.co.uk systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
   Jul 22 13:00:22 confluence.syzygy.co.uk kill[25953]: kill: cannot find process ""
   Jul 22 13:00:22 confluence.syzygy.co.uk systemd[1]: httpd.service: control process exited, code=exited status=1
   Jul 22 13:00:22 confluence.syzygy.co.uk systemd[1]: Failed to start The Apache HTTP Server.
   Jul 22 13:00:22 confluence.syzygy.co.uk systemd[1]: Unit httpd.service entered failed state.

日志中似乎没有任何相关内容,除了:

[ssl:warn] [pid 25447] AH01916: Init: (confluence.company.co.uk:443) You configured HTTP(80) on the standard HTTPS(443) port! 

这与 HTTPd 未启动分开发生

更新 2

所以我通过将以下内容移入 ssl.conf 中的虚拟主机来解决这个问题:

    SSLProxyEngine On
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://confluence.company.co.uk:8091/
    ProxyPassReverse / http://confluence.company.co.uk:8091/

为什么我可以在单独的虚拟主机中使用它?

【问题讨论】:

    标签: apache tomcat https proxy centos


    【解决方案1】:

    您忘记将 ServerName confluence.company.co.uk 添加到您的 433 虚拟主机。这可能会导致 httpd 默认使用不同的 TLS 虚拟主机。

    【讨论】:

    • httpd不想启动时会告诉你什么?我很难相信它会拒绝 servername 指令。检查您的错误日志,让我们知道它的内容:)
    • httpd 错误日志本身说明了什么? wiki.apache.org/httpd/DistrosDefaultLayout 会告诉你在哪里可以找到日志。
    • 我必须查看整个 httpd 配置来解决这个问题。您要么配置端口 443 两次,要么在某处的 ServerName 指令中有错误。
    • 我在 pastebin 上包含了指向 ssl.conf 和 httpd.conf 的链接
    • 您的配置中有ServerName confluence.company.co.uk:443。请删除其中的 ':443' 部分,然后重试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2017-09-25
    • 2011-11-10
    • 2015-11-11
    • 2023-03-23
    • 2012-09-06
    相关资源
    最近更新 更多