Apache 2.4 和 VirtualHosts 的問題

Apache 2.4 和 VirtualHosts 的問題

有人可以告訴我我在這裡做錯了什麼嗎,我有 1 台運行 Apache 2.4 的伺服器,其中有 3 個虛擬主機,設定如下:

<VirtualHost helpedsk.example.com:80>
ServerAdmin [email protected]
DocumentRoot "${SRVROOT}/htdocs/hesk"
ServerName helpdesk.example.com
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
    <Directory "${SRVROOT}/htdocs/hesk">
        Require all granted
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost wiki.example.com:80>
    ServerAdmin [email protected]
    DocumentRoot "${SRVROOT}/htdocs/dokuwiki"
    ServerName wiki.example.com
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
    <Directory "${SRVROOT}/htdocs/dokuwiki">
        Require all granted
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

</VirtualHost>

<VirtualHost docs.example.com:80>
    ServerAdmin [email protected]
    DocumentRoot "${SRVROOT}/htdocs/drupal"
    ServerName docs.example.com
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
    <Directory "${SRVROOT}/htdocs/drupal">
        Require all granted
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

但由於某種原因,只有最後一個有效,第一個向我顯示伺服器的文檔根目錄(沒有 hesk),第二個進入無限重定向到自身,我不明白為什麼,第二個可能必須這樣做,因為我將其設定為指向伺服器ip/dokuwiki,我可以稍後更改它,但為什麼第一個不會被詢問?

當使用 serverip/site 存取時,所有這些網站都可以正常工作,但是當嘗試透過名稱存取時,只有最後一個網站可以工作。

答案1

沒關係,我將所有 VirtualHost 行更改為 *:80,將 ServerName 與網站 url 一起保留在其中,現在可以使用了。

相關內容