我有一台带有三个虚拟主机的服务器,分别是默认 (domain.com)、site1.com 和 site2.com。该服务器运行的是带有 Apache2 的 Ubuntu 22.04 LTS。直到昨天,这台服务器只为默认域、一个简单的手工站点和包含 Wordpress 站点的 site1.com 提供服务,并且没有任何问题。我使用的是带有 LetsEncrypt 证书的 HTTPS。
昨天,我安装了 site2.com,并在那里打开了第二个 Wordpress 实例。现在,site1.com 和 domain.com 可以正常工作,但 site2.com 会打开 site1.com除了当我打字时www.site2.com。只需输入 site2.com 即可打开 site1.com。
我彻底糊涂了。有人能告诉我哪里出了问题吗?
这是我的虚拟主机文件:
000-默认.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
000-默认-le-ssl.conf
<IfModule mod_ssl.c>
SSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName domain.com
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Header always set Strict-Transport-Security "max-age=31536000"
SSLUseStapling on
</VirtualHost>
</IfModule>
站点1.conf
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot "/var/www/site1.com/"
ErrorLog "/var/log/apache2/site1_com_error_log"
TransferLog "/var/log/apache2/site1_com__access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
站点1-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot "/var/www/site1.com/"
ErrorLog "/var/log/apache2/site1_com_error_log"
TransferLog "/var/log/apache2/site1_com__access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =site1.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site1.com/privkey.pem
</VirtualHost>
</IfModule>
站点2.conf
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot "/var/www/site2.com/"
ErrorLog "/var/log/apache2/site2_com_error_log"
TransferLog "/var/log/apache2/site2_com_access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
站点2-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot "/var/www/site2.com/"
ErrorLog "/var/log/apache2/site2_com_error_log"
TransferLog "/var/log/apache2/site2_com_access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/site2.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site2.com/privkey.pem
</VirtualHost>
</IfModule>
我的主机文件中有以下内容:
127.0.0.1 localhost
127.0.0.1 site1.com
127.0.0.1 site2.com
127.0.0.1 domain.com