Ubuntu 23.04 Apache2バーチャルホストの設定方法
環境
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 23.04
Release: 23.04
Codename: lunar
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 23.04
Release: 23.04
Codename: lunar
# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 23.04 Release: 23.04 Codename: lunar
apacheのバージョン
# apachectl -v
Server version: Apache/2.4.55 (Ubuntu)
Server built: 2023-03-08T16:32:34
# apachectl -v
Server version: Apache/2.4.55 (Ubuntu)
Server built: 2023-03-08T16:32:34
# apachectl -v Server version: Apache/2.4.55 (Ubuntu) Server built: 2023-03-08T16:32:34
操作方法
1.バーチャルホストのディレクトリ「/var/www/virtual.hosts」を作成する
# mkdir /var/www/virtual.hosts
# mkdir /var/www/virtual.hosts
# mkdir /var/www/virtual.hosts
2.バーチャルホストで運用するドメイン名 を、
ドキュメントルート [/var/www/virtual.hosts] ディレクトリに割り当てて設定します。
# vi /etc/apache2/sites-available/virtual.hosts.conf
# vi /etc/apache2/sites-available/virtual.hosts.conf
# vi /etc/apache2/sites-available/virtual.hosts.conf
バーチャルホストのドメインの設定を行います
<VirtualHost *:80>
DocumentRoot /var/www/virtual.hosts
ServerName xxx
ServerAdmin xxxx
ErrorLog /var/log/apache2/virtual.hosts.error.log
CustomLog /var/log/apache2/virtual.hosts.access.log combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/virtual.hosts
ServerName xxx
ServerAdmin xxxx
ErrorLog /var/log/apache2/virtual.hosts.error.log
CustomLog /var/log/apache2/virtual.hosts.access.log combined
</VirtualHost>
<VirtualHost *:80> DocumentRoot /var/www/virtual.hosts ServerName xxx ServerAdmin xxxx ErrorLog /var/log/apache2/virtual.hosts.error.log CustomLog /var/log/apache2/virtual.hosts.access.log combined </VirtualHost>
3.設定内容を反映します
# a2ensite virtual.hosts
Enabling site virtual.hosts.
To activate the new configuration, you need to run:
systemctl reload apache2
# a2ensite virtual.hosts
Enabling site virtual.hosts.
To activate the new configuration, you need to run:
systemctl reload apache2
# a2ensite virtual.hosts Enabling site virtual.hosts. To activate the new configuration, you need to run: systemctl reload apache2
4.apache2を再起動します
# systemctl reload apache2