Debian 11 Bullseye
Sponsored Link

Apache2 : バーチャルホストの設定2021/09/07

 
バーチャルホストを有効化して、複数のドメイン名を利用できるように設定します。
[1] 例として、バーチャルホストで運用するドメイン名 [virtual.host] を、ドキュメントルート [/var/www/virtual.host] ディレクトリに割り当てて設定します。
root@www:~#
vi /etc/apache2/sites-available/virtual.host.conf
# 新規作成

# バーチャルホストのドメインの設定
<VirtualHost *:80>
    DocumentRoot /var/www/virtual.host
    ServerName www.virtual.host
    ServerAdmin webmaster@virtual.host
    ErrorLog /var/log/apache2/virtual.host.error.log
    CustomLog /var/log/apache2/virtual.host.access.log combined
</VirtualHost>

<Directory "/var/www/virtual.host">
    Options FollowSymLinks
    AllowOverride All
</Directory>

root@www:~#
a2ensite virtual.host

Enabling site virtual.host.
To activate the new configuration, you need to run:
  systemctl reload apache2

root@www:~#
systemctl restart apache2

[2] テストページを作成して動作確認をします。クライアントコンピューターで Web ブラウザを起動し、作成したテストページにアクセスできれば OK です。
root@www:~#
mkdir /var/www/virtual.host

root@www:~#
vi /var/www/virtual.host/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Virtual Host Test Page
</div>
</body>
</html>
関連コンテンツ