据我所知,ServerAlias 一次只匹配一个域。添加异常的唯一方法是不使用该域的 ServerAlias。
如果你不想让VirtualHost匹配xx.com,那么不要把ServerAlias xx.com放在VirtualHost中,你应该没问题吧?
我猜这不是你的问题,因为这很明显,所以让我猜猜你可能会问的其他问题:
如果您正在寻求一种方法来执行匹配多个域的通配符 ServerAlias,您可能应该使用 mod_rewrite 而不是依赖 Apache 的 VirtualHost 有限解析。它非常强大且基于正则表达式,可以处理各种通配符和模式。
另一方面,如果您想为 xx.com 上的特定 URL 添加异常并将该 URL 指向不同的 VirtualHost,也可以使用 mod_rewrite 完成。
简而言之,看看 mod_rewrite,看看它是否能帮助你做你需要做的事情。
我还想到,您可能会混淆第一个 VirtualHost 的行为。第一个 VirtualHost 始终是默认值。如果没有其他 VirtualHost 匹配,则第一个将始终用于 Apache 接收的任何域。从默认 VirtualHost 中“排除”域的唯一方法是添加自己的特定 VirtualHost 来捕获它。无论如何,mod_rewrite 很可能也会成为你的朋友。
编辑:这是我的 VirtualHost 配置中的一个 sn-p,也许这会帮助你理解我告诉你要做什么:
<VirtualHost *:80>
# This is the default VirtualHost, because it is listed first.
# All domain names that are not recognized elsewhere go here
# automatically. All this VirtualHost does is to display a simple
# HTML page informing users that no site exists at that address.
# ServerName/Alias doesn't matter, because it's not a real vhost
ServerName default-vhost.mysite.net
DocumentRoot /var/www/nosite
# In case someone goes to http://unknownsite.com/something/else.html
# make sure they get the "no site" message, so redirect all URLs.
RewriteEngine On
RewriteRule ^/(..*) /index.html [NS]
</VirtualHost>
<VirtualHost *:80>
# This is my real website. Because it is listed second, it will ONLY
# be accessible from hostnames listed as ServerName or ServerAlias
ServerName mysite.net
DocumentRoot /var/www/mysite
</VirtualHost>