![如何通过 VirtualHost 使用多个站点正确配置“apache2”?](https://linux22.com/image/765805/%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87%20VirtualHost%20%E4%BD%BF%E7%94%A8%E5%A4%9A%E4%B8%AA%E7%AB%99%E7%82%B9%E6%AD%A3%E7%A1%AE%E9%85%8D%E7%BD%AE%E2%80%9Capache2%E2%80%9D%EF%BC%9F.png)
我使用apache2中的“VirtualHost”方法配置了两个站点,但是当我调用我的站点时,如果第一个配置文件出现错误,它就会进入第二个站点。我的配置文件是:
1:音频城堡.现场直播:
<VirtualHost *:80>
Protocols h2
Redirect / https://audio-castle.live
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
Protocols h2
ServerName audio-castle.live
ServerAlias www.audio-castle.live
ServerAdmin
DocumentRoot /var/www/audiocastle/web
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/audio-castle.live/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/audio-castle.live/privkey.pem
<Directory /var/www/audiocastle/web>
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
第二个文件是:gtdvm.com:
<VirtualHost *:80>
ServerName gtdvm.com
Redirect / https://gtdvm.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName gtdvm.com
ServerAlias www.gtdvm.com
ServerAdmin
DocumentRoot /var/www/gtdvm.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/gtdvm.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/gtdvm.com/privkey.pem
<Directory /var/www/gtdvm.com>
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
问题是,当这两个文件之一出现错误时,例如当我访问 audio-castle.live 时,如果错误出在 audio-castle.live 文件中,我会到达站点 gtdvm.com。我的问题是:当其中一个站点遇到错误时,如何避免从一个站点重定向到另一个站点?我使用 Ubuntu 20.04,apache2.4.46。