バーチャルホストの設定(AlmaLinux9)
提供: すだちWiki
メインページ > Category:自宅サーバー > AlmaLinux 9 で自宅サーバー構築 > バーチャルホストの設定(AlmaLinux9)
- すでに稼働しているWebサーバー(Apache)にバーチャルホストの設定を行ったので忘れないために書いておく。
バーチャルホスト設定
バーチャルホスト用ドキュメントルートディレクトリ作成
- 全ての、ドメイン名で作成。
[root@host2 ~]# mkdir /var/www/html/awajp.com [root@host2 ~]# mkdir /var/www/html/eeljp.com
ディレクトリの所有者変更
- 全ての、ドメイン名の所有者変更。
[root@host2 ~]# chown -R sysop. /var/www/html/
未定義ホスト用バーチャルホスト設定ファイル作成
※バーチャルホスト未定義ホスト名でアクセス時にアクセスを拒否する
[root@host2 ~]# vi /etc/httpd/conf.d/virtualhost-00.conf
<VirtualHost _default_:80>
ServerName any
<Location />
Require all denied
</Location>
</VirtualHost>
メインホスト用バーチャルホスト設定ファイル作成
[root@host2 ~]# vi /etc/httpd/conf.d/virtualhost-awajp.com.conf
<VirtualHost *:80>
ServerName awajp.com
ServerAlias www.awajp.com
DocumentRoot /var/www/html/awajp.com
</VirtualHost>
追加ホスト用バーチャルホスト設定ファイル作成
[root@host2 ~]# vi /etc/httpd/conf.d/virtualhost-eeljp.com.conf
<VirtualHost *:80>
ServerName eeljp.com
ServerAlias wwww.eeljp.com
DocumentRoot /var/www/html/eeljp.com
ErrorLog logs/eeljp.com-error_log
CustomLog logs/eeljp.com-access_log combined
</VirtualHost>
「httpd.conf」の文法チェック
[root@host2 ~]# apachectl configtest Syntax OK
Webサーバー再起動
[root@host2 ~]# systemctl restart httpd
動作確認
[root@host2 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 土 2017-05-06 13:45:58 JST; 46s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 29305 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 29311 (httpd)
Status: "Total requests: 9; Current requests/sec: 0.111; Current traffic: 1.3KB/sec"
CGroup: /system.slice/httpd.service
├─29311 /usr/sbin/httpd -DFOREGROUND
├─29312 /usr/sbin/httpd -DFOREGROUND
├─29313 /usr/sbin/httpd -DFOREGROUND
├─29314 /usr/sbin/httpd -DFOREGROUND
├─29315 /usr/sbin/httpd -DFOREGROUND
├─29316 /usr/sbin/httpd -DFOREGROUND
├─29317 /usr/sbin/httpd -DFOREGROUND
├─29318 /usr/sbin/httpd -DFOREGROUND
├─29322 /usr/sbin/httpd -DFOREGROUND
├─29323 /usr/sbin/httpd -DFOREGROUND
└─29324 /usr/sbin/httpd -DFOREGROUND
5月 06 13:45:57 host3.sudachi.jp systemd[1]: Starting The Apache HTTP Server...
5月 06 13:45:58 host3.sudachi.jp systemd[1]: Started The Apache HTTP Server.
