Apache2 配置 - AWS Linux 2 上的虚拟主机 IP

Apache2 配置 - AWS Linux 2 上的虚拟主机 IP

/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>


这是可行的,但是当我用 URL 替换星号时,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 将允许所有网络接口访问该虚拟主机。我认为您遇到的行为是您正在访问默认文档根目录,因为您设置的虚拟主机均未打开

相关内容