無法讓虛擬主機運作,請看看我做錯了什麼(CentOS 6.0)

無法讓虛擬主機運作,請看看我做錯了什麼(CentOS 6.0)

vhost.conf ,位於 etc/httpd/vhost.d/

NameVirtualHost *:80

    <VirtualHost *:80>
         ServerAdmin [email protected]
         ServerName localhost
         ServerAlias localhost.example.com
         DocumentRoot /var/www/html/example.com/public_html/
         ErrorLog /var/www/html/example.com/logs/error.log
         CustomLog /var/www/html/example.com/logs/access.log combined
    </VirtualHost>

    <VirtualHost *:80>
         ServerAdmin [email protected]
         ServerName example.org
         ServerAlias www.example.org
         DocumentRoot /var/www/html/example.org/public_html/
         ErrorLog /var/www/html/example.org/logs/error.log
         CustomLog /var/www/html/example.org/logs/access.log combined
    </VirtualHost>

httpd.conf,預設設置,添加到最後:

Include /etc/httpd/vhosts.d/*.conf

根目錄:

DocumentRoot "/var/www/html"

在上述資料夾中建立的虛擬主機的相應目錄。權限看起來都正確。每個目錄中的 Index.php 檔案public_html。然而,當我現在輸入 localhost 時,它只會帶我到預設的 apache 2 頁面,我是否應該Include /etc/httpd/vhosts.d/*.conf從預設目錄中刪除 webserver Works as required 行,為我放在那裡的任何索引檔案提供服務。

答案1

根據輸入的內容,聽起來您沒有語法錯誤。因此,請在 /etc/hosts 檔案中執行此操作(如果您直接從伺服器執行此操作):

127.0.0.1   example.org
127.0.0.1   example.com

或是在你的電腦的主機檔案中:

YOURSERVERIP  example.org
YOURSERVERIP  example.com

並瀏覽到該網域而不是本機。

您只看到 apache 網頁的原因是 Apache 需要知道要訪問哪個頁面 - 因為您還沒有 DNS 設置,所以不會向 Apache 發送任何帶有相關主機名的內容,因此它默認為文檔根目錄。

答案2

由於 Include 行位於您的 VirtualHosts 之後,我猜想其中包含的虛擬主機之一會覆蓋您的新虛擬主機。 “httpd -S”說什麼? (它可能不是“httpd”,它可能是“apache2”或其他)。 -S 標誌將顯示您已設定的所有虛擬主機,並有助於除錯。

您可以嘗試刪除包含行,看看這是否使您的新區塊起作用。您也可以檢查錯誤日誌以查看是否有有關您的設定檔的任何警告。

相關內容