Debian 10 Buster
Sponsored Link

Apache2 : バーチャルホストの設定2019/08/01

 
バーチャルホストを設定し、複数のドメイン名を利用できるようにします。
例として、バーチャルホストで運用するドメイン名 [virtual.host] を、一般ユーザー [debian] のホームディレクトリ領域 (/home/debian/public_html) に割り当ててアクセスできるように設定します。
当例のように一般ユーザー領域を利用する場合は事前に Userdir の設定も必要です
[1] バーチャルホストの設定です。
root@www:~#
vi /etc/apache2/sites-available/virtual.host.conf
# virtual.host用設定ファイル新規作成

<VirtualHost *:80>
    ServerName www.virtual.host
    ServerAdmin webmaster@virtual.host
    DocumentRoot /home/debian/public_html
    ErrorLog /var/log/apache2/virtual.host.error.log
    CustomLog /var/log/apache2/virtual.host.access.log combined
    LogLevel warn
</VirtualHost>

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] 設定したユーザーでテストページを作成し、動作確認をします。正常にページが表示されれば OK です。
debian@www:~$
mkdir ~/public_html

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