0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Rocky Linux 9】08.バーチャルホスト設定(Apache)

Posted at

バーチャルホスト設定

IPアドレスのドキュメントルートは「/var/www/html」、バーチャルホストのドキュメントルートは「/var/www/バーチャルホスト名」とする
ログファイルもバーチャルホスト用のディレクトリを作成して保存するようにし、ログローテートスクリプトも編集する

ローカルホスト用バーチャルホスト設定

/etc/httpd/conf.d/virtualhost.localhost.conf
<VirtualHost *:80>
    ServerName      localhost
    DocumentRoot    /var/www/html
    ErrorLog        logs/error_log
    CustomLog       logs/access_log combined env=!nolog
</VirtualHost>

メインホスト用バーチャルホスト設定

/etc/httpd/conf.d/virtualhost.example.com.conf
<VirtualHost *:80>
    ServerName      example.com
    DocumentRoot    /var/www/example.com
    ErrorLog        logs/example.com/error_log
    CustomLog       logs/example.com/access_log combined env=!nolog
</VirtualHost>

メインホスト用ディレクトリ設定

mkdir /var/www/example.com
chmod 777 /var/www/example.com
mkdir /var/log/httpd/example.com

Apache再起動

systemctl restart httpd

logrotateスクリプト修正

/etc/logrotate.d/httpd
# Note that logs are not compressed unless "compress" is configured,
# which can be done either here or globally in /etc/logrotate.conf.
- /var/log/httpd/*log {
+ /var/log/httpd/*log /var/log/httpd/*/*log {
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
    endscript
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?