Linux
Apache2 配置 - AWS Linux 2 上的虛擬主機 IP
/etc/httpd/conf.d/vhosts.conf
:<VirtualHost *:80> ServerAdmin admin@example.io 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 dev@example.io 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>
這可行,但是當我用 url 替換星號時,
DocumentRoot
預設為/var/www/html
:<VirtualHost example.io:80> ServerAdmin admin@example.io 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 dev@example.io 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
我可以使用星號,我只是想了解為什麼在這種情況下必須這樣做。
該部分僅定義可以到達該虛擬主機的 ip。在這種情況下,這
<VirtualHost *:80>
意味著 apache 將讓所有網路介面訪問該虛擬主機。我認為您遇到的行為是您正在進入預設文件根目錄,因為您設置的虛擬主機都沒有打開