/etc/httpd/conf.d/vhosts.conf
:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/vhosts/main-repo-dir"
ServerName example.io
ErrorLog "logs/example.io-error_log"
CustomLog "logs/example.io-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/vhosts/dev-repo-dir"
ServerName dev.example.io
ErrorLog "logs/dev.example.io-error_log"
CustomLog "logs/dev.example.io-access_log" common
</VirtualHost>
這是可行的,但是當我用網址替換星號時,DocumentRoot
預設為/var/www/html
:
<VirtualHost example.io:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/vhosts/main-repo-dir"
ServerName example.io
ErrorLog "logs/example.io-error_log"
CustomLog "logs/example.io-access_log" common
</VirtualHost>
<VirtualHost dev.example.io:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/vhosts/dev-repo-dir"
ServerName dev.example.io
ErrorLog "logs/dev.example.io-error_log"
CustomLog "logs/dev.example.io-access_log" common
</VirtualHost>
/etc/hosts
:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost6 localhost6.localdomain6
127.0.0.1 example.io
127.0.0.1 dev.example.io
我可以使用星號,我只是想了解為什麼在這種情況下必須這樣做。
答案1
該部分僅定義可到達該虛擬主機的 ip。在這種情況下,這<VirtualHost *:80>
意味著 apache 將允許所有網路介面存取該虛擬主機。我認為您遇到的行為是您正在訪問預設文檔根目錄,因為您設定的虛擬主機都沒有打開