【问题标题】:Apache always loads the same vhostApache 总是加载相同的虚拟主机
【发布时间】:2019-02-21 09:43:43
【问题描述】:

我有以下虚拟主机。然而,当使用 https 时,虚拟主机似乎总是解析为 app.home,使其加载 cloud.home 的唯一方法是从虚拟主机中删除 app.home。这让我相信它忽略了 ServerName 设置。

app.home.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
   ServerName app.home
  ProxyPreserveHost On
  ProxyRequests off
  ProxyPass /api/websocket ws://localhost:8123/api/websocket disablereuse=on keepalive=on
  ProxyPassReverse /api/websocket ws://localhost:8123/api/websocket disablereuse=on
  ProxyPass / http://localhost:8123/ disablereuse=on keepalive=on
  ProxyPassReverse / http://localhost:8123/ disablereuse=on#`

  RewriteEngine on
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)  ws://localhost:8123/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)  http://localhost:8123/$1 [P,L]

SSLCertificateFile /etc/letsencrypt/live/app.home/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/app.home/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

cloud.home.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName cloud.home
    DocumentRoot "/var/www/cloud"

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/cloud/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/cloud.home.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/cloud.home.access.log combined

SSLCertificateFile /etc/letsencrypt/live/cloud.home/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cloud.home/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

【问题讨论】:

    标签: apache virtualhost


    【解决方案1】:

    Apache 在端口 443 上接收到一个加密连接。然后它与客户端的浏览器协商证书。但此时,它还没有读取请求的域。它必须首先协商证书才能解密有效负载。

    因此 Apache 将始终使用它找到的第一个与端口 443 匹配的 VirtualHost。它从这个虚拟主机获取证书。

    要解决这个问题,您必须:

    • 为您的第二个域设置第二个 IP。因此 Apache 将被配置为 domain1 == IP1, domain2 == IP2。
    • 为第二个域使用不同的端口,例如:444。但这并不方便,因为它不是默认设置。
    • 使用 SNI。对此做一些研究,这里的解释太长了。

    【讨论】:

    猜你喜欢
    • 2016-06-13
    • 2018-07-08
    • 2019-11-14
    • 1970-01-01
    • 2017-01-02
    • 2011-06-19
    • 2012-07-08
    • 2017-02-06
    • 2019-08-25
    相关资源
    最近更新 更多