![尽管服务器名称与端口 80 匹配,Apache 虚拟主机仍为端口 443 提供默认虚拟主机](https://linux22.com/image/622185/%E5%B0%BD%E7%AE%A1%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%8D%E7%A7%B0%E4%B8%8E%E7%AB%AF%E5%8F%A3%2080%20%E5%8C%B9%E9%85%8D%EF%BC%8CApache%20%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%E4%BB%8D%E4%B8%BA%E7%AB%AF%E5%8F%A3%20443%20%E6%8F%90%E4%BE%9B%E9%BB%98%E8%AE%A4%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA.png)
我有两台服务器,除了一些小的配置更改外,它们都是彼此的克隆。当我尝试访问它们的 surveillance.*.com 子域时,出现了一些意外行为。
在每台服务器上运行./apache2ctl -S
结果如下:
临时服务器
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server 010.staging.com (/etc/apache2/sites-enabled/010:2)
port 443 namevhost 010.staging.com (/etc/apache2/sites-enabled/010:2)
port 443 namevhost 011.staging.com (/etc/apache2/sites-enabled/011:2)
port 443 namevhost 013.staging.com (/etc/apache2/sites-enabled/013:2)
*:80 is a NameVirtualHost
default server www.production.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost www.production.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost monitoring.staging.com (/etc/apache2/sites-enabled/monitoring:1)
Syntax OK
生产服务器
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server de.production.com (/etc/apache2/sites-enabled/de:2)
port 443 namevhost de.production.com (/etc/apache2/sites-enabled/de:2)
port 443 namevhost uk.production.com (/etc/apache2/sites-enabled/uk:2)
port 443 namevhost us.production.com (/etc/apache2/sites-enabled/us:2)
port 443 namevhost www.production.com (/etc/apache2/sites-enabled/production:2)
*:80 is a NameVirtualHost
default server www.production.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost www.production.com (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost monitoring.production.com (/etc/apache2/sites-enabled/monitoring:1)
Syntax OK
两台服务器上000-default的配置如下
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.production.com
DocumentRoot /home/user/apache/
RewriteEngine on
RewriteLog /var/log/apache2/log
RewriteLogLevel 1
RewriteCond %{REQUEST_URI}/ !^(/server-status).*$
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
</VirtualHost>
我遇到的问题是,当我访问时,http://monitoring.staging.com
我被重定向到默认安全端口服务器http**s**.monitoring.staging.com
并提供应用程序。010.staging.com
生产服务器运行正常,并为我的应用程序监控工具提供服务。
正如我所说,这两台服务器都是从主映像的克隆开始的,只有非常小的配置变化——如果需要,我可以描述具体的更改。
有人能猜一下我为什么会看到这种行为吗?
谢谢
更新:
这是用于监控的 Vhost 配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName monitoring.staging.com
DocumentRoot /var/www/munin
<Directory /var/www/munin>
Options FollowSymLinks
AllowOverride None
</Directory>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel notice
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
ServerSignature On
</VirtualHost>
对于实际正在服务的应用程序:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName 010.staging.com
RewriteLog /var/log/apache2/ssl.log
RewriteRule ^/$ /010/home.htm [R=301,L]
RewriteRule ^/(?!010/|static/|mgt).*$ /010/home.htm [R=301,L]
SSLCertificateKeyFile /etc/apache2/ssl/010/apache.key
SSLCertificateFile /etc/apache2/ssl/010/apache.crt
SSLCACertificateFile /etc/apache2/ssl/010/apache-ca.crt
</VirtualHost>
</IfModule>
答案1
我通过将000-default
暂存配置更改为以下内容来解决这个问题:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName staging.com
DocumentRoot /home/user/apache/
RewriteEngine on
RewriteLog /var/log/apache2/log
RewriteLogLevel 1
RewriteCond %{REQUEST_URI}/ !^(/server-status).*$
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
</VirtualHost>
ServerName 从 www.production.com 更改为 staging.com
我不知道为什么这解决了这个问题,所以我非常乐意为任何可以解释这种行为以及 Apache 正在做什么的人给出正确的答案。