以下の内容はhttps://souiunogaii.hatenablog.com/entry/apache24-virtualhostsより取得しました。


AlmaLinux9.6+Apache2.4にバーチャルホストを設定、1台のサーバーで複数サイトを運用

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・Apache2.4でバーチャルホストで複数のサイトを運用する方法を知りたい。
・具体的な手順を分かりやすく教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. AlmaLinux9.6+Apache2.4にバーチャルホストを設定、1台のサーバーで複数サイトを運用する手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

AlmaLinux9.6+Apache2.4にバーチャルホストを設定、1台のサーバーで複数サイトを運用

デフォルトのアクセス拒否用conf作成

/etc/httpd/conf.d/virtualhost-a-webap01.conf
<VirtualHost _default_:80>
    ServerName any
    <Location />
        Require all denied
    </Location>
</VirtualHost>

テスト用バーチャルホスト1個目のconf作成

/etc/httpd/conf.d/test01.blue-planet.internal.conf
## VirtualHost01 test01.blue-planet.internal
<VirtualHost *:80>
ServerName test01.blue-planet.internal
ServerAlias www.test01.blue-planet.internal
ServerAdmin root@blue-planet.internal
DocumentRoot "/var/www/html/test01"
<Directory "/var/www/html/test01">
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
ErrorLog logs/test01.blue-planet.internal-error_log
CustomLog logs/test01.blue-planet.internal-access_log combined
</VirtualHost>

テスト用バーチャルホスト2個目のconf作成

/etc/httpd/conf.d/test02.blue-planet.internal.conf
## VirtualHost02 test02.blue-planet.internal
<VirtualHost *:80>
ServerName test02.blue-planet.internal
ServerAlias www.test02.blue-planet.internal
ServerAdmin root@blue-planet.internal
DocumentRoot "/var/www/html/test02"
<Directory "/var/www/html/test02">
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
ErrorLog logs/test02.blue-planet.internal-error_log
CustomLog logs/test02.blue-planet.internal-access_log combined
</VirtualHost>

ドキュメントルート用ディレクトリ作成

[root@a-webap01 ~]# mkdir /var/www/html/test01
[root@a-webap01 ~]# mkdir /var/www/html/test02

index.htmlの作成

[root@a-webap01 ~]# vi /var/www/html/test01/index.html
[root@a-webap01 ~]# vi /var/www/html/test02/index.html

確認

[root@a-webap01 ~]# httpd -t
Syntax OK

httpd再起動して設定を反映

[root@a-webap01 ~]# systemctl restart httpd



以上の内容はhttps://souiunogaii.hatenablog.com/entry/apache24-virtualhostsより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14