Apache-2.2

使用 catch all *(wildcard) 別名從 Apache2 serverAlias 中排除特定域

  • July 6, 2021

我有一個需要支持自定義域的 Web 應用程序,在這方面我設置了以下基於名稱的虛擬伺服器:

<VirtualHost *:80>
   ServerName example.com
   ServerAlias * *.example.com www.example.com example.com
   RailsEnv production
   RackEnv production
   DocumentRoot /srv/www/example/current/public
   <Directory /srv/www/example/current/public>
            AllowOverride all
            Options -MultiViews FollowSymLinks
   </Directory>
   ErrorLog /srv/www/example/log/error.log
   TransferLog /srv/www/example/log/access.log
</VirtualHost>

注意 * 作為伺服器別名?擷取該伺服器上的所有域。但是,我在此伺服器上還有其他站點,我希望將其排除在此列表之外。對我來說,擁有一個排除域列表比手動設置使用者可以在此服務上註冊的每個域作為 serverAlias 更經濟……

也許這不是最好的方法,但我正在尋求幫助,以最好(相對簡單)的方式設置一個可以擷取任何域的網路應用程序,同時允許將其他特定域路由到不同的應用程序.

Apache 按照定義域的順序搜尋匹配項。

如果我正確理解您的問題,那麼可以通過在擷取所有主機之前定義要排除的主機來解決它。

例子:

<VirtualHost *:80>
   ServerName excluded.example.com
   ServerAlias  something.example.com ...
   ...
</VirtualHost>
<VirtualHost *:80>
   ServerName example.com
   ServerAlias * *.example.com www.example.com example.com
   RailsEnv production
   ...
</VirtualHost>

引用自:https://serverfault.com/questions/332730