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 はすべてのネットワーク インターフェイスにその仮想ホストへのアクセスを許可することになります。設定している仮想ホストがどれも開いていないため、デフォルトのドキュメント ルートにアクセスしていると考えられます。

関連情報