我使用 Win10、Apache2.4 和 PHP7.4。我在 Apache24\htdocs 中創建了 2 個測驗站點 - Test.com 和 Test2.com,都包含簡單的 index.php 檔案。以下是組態檔中的例外情況:
主持人:
127.0.0.1 Test.com www.Test.com
127.0.0.1 Test2.com www.Test2.com
httpd.conf:
# PHP7 module
PHPIniDir "C:/Dev/PHP-7.4.24"
LoadModule php7_module "C:/Dev/PHP-7.4.24/php7apache2_4.dll"
AddType application/x-httpd-php .php
httpd-vhosts.conf:
<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
ServerName www.example.com:80
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "${SRVROOT}/htdocs/Test.com"
ServerName Test.com
ServerAlias www.Test.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "${SRVROOT}/htdocs/Test2.com"
ServerName Test2.com
ServerAlias www.Test2.com
</VirtualHost>
當同時加載 test.com 和 test2.com 時,瀏覽器會顯示 htdocs 的檔案夾索引。僅單擊任一索引顯示實際站點,并且瀏覽器地址欄位變為,例如http://test.com/Test.com/。如何配置apache以從地址顯示站點test.com?
uj5u.com熱心網友回復:
<VirtualHost *:80>
</VirtualHost
嘿 apache 如果您在埠 80 上收到任何請求,請轉到檔案夾 test.com
嘿 apache 如果您在埠 80 上收到任何請求,請轉到檔案夾 test2.com
哦!
因此,如果我發出 localhost 請求http://127.0.0.1:80 apache 應該神奇地知道要轉到哪個檔案夾?
uj5u.com熱心網友回復:
加載
test.com和 時test2.com,瀏覽器顯示 的檔案夾索引htdocs。
如果ServerName(or ServerAlias) 指令與請求中請求的Host標頭不匹配,則會發生這種情況。然后它將默認為第一個<VirtualHost>.
ServerName Test.com ServerAlias www.Test.com
我不一定希望這是區分大小寫的,但是您已經將ServerNameas Test.com(capital T)定義為(capital ),但是您正在請求test.com(全部小寫) - 無論如何,瀏覽器都會自動將 HTTP 請求中的主機名小寫,因此您不能實際提出請求Test.com。
您應該將 定義ServerName為全小寫。
ServerName test.com
ServerAlias www.test.com
127.0.0.1 Test.com www.Test.com 127.0.0.1 Test2.com www.Test2.com
同樣,這也應該是小寫的。
僅單擊任一索引顯示實際站點,并且瀏覽器地址欄位變為,例如,
http://test.com/Test.com/
看起來您錯誤地鏈接到/Test.com子目錄,而不是http://test.com主機?
我試圖完全注釋掉這個塊 - 沒有任何改變。
在容器外的主服務器配置中是否有類似的默認值<VirtualHost>?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/324610.html
上一篇:如何使用混合分隔符(即方括號、空格和雙引號)來決議日志(nginx/apacheaccess.log)?并可選擇轉換為json
