Apache 始终加载相同的虚拟主机
Apache always loads the same vhost
我有以下虚拟主机。然而,当使用 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/ [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:8123/ [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 在端口 443 上接收加密连接。然后它与客户端的浏览器协商证书。但此时,它 尚未 读取请求的域。它必须先协商证书才能解密有效负载。
因此 Apache 将始终使用它找到的第一个与端口 443 匹配的 VirtualHost。它从中获取证书。
要解决这个问题,您必须:
- 为您的第二个域设置第二个 IP。因此 Apache 将被配置为 domain1 == IP1,domain2 == IP2。
- 为第二个域使用不同的端口,例如 :444。但这并不方便,因为它不是默认值。
- 使用 SNI。做一些研究,在这里解释太长了。
我有以下虚拟主机。然而,当使用 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/ [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:8123/ [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 在端口 443 上接收加密连接。然后它与客户端的浏览器协商证书。但此时,它 尚未 读取请求的域。它必须先协商证书才能解密有效负载。
因此 Apache 将始终使用它找到的第一个与端口 443 匹配的 VirtualHost。它从中获取证书。
要解决这个问题,您必须:
- 为您的第二个域设置第二个 IP。因此 Apache 将被配置为 domain1 == IP1,domain2 == IP2。
- 为第二个域使用不同的端口,例如 :444。但这并不方便,因为它不是默认值。
- 使用 SNI。做一些研究,在这里解释太长了。