Ubuntu 23.04 Apache2バーチャルホストの設定方法

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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のバージョン

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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」を作成する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# mkdir /var/www/virtual.hosts
# mkdir /var/www/virtual.hosts
# mkdir /var/www/virtual.hosts

2.バーチャルホストで運用するドメイン名  を、
ドキュメントルート [/var/www/virtual.hosts] ディレクトリに割り当てて設定します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# vi /etc/apache2/sites-available/virtual.hosts.conf
# vi /etc/apache2/sites-available/virtual.hosts.conf
# vi /etc/apache2/sites-available/virtual.hosts.conf

バーチャルホストのドメインの設定を行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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.設定内容を反映します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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

 

Ubuntu 23.04

Posted by arkgame