Apache httpd:バーチャルホストを作る
/etc/apache2/site-available/*.conf にバーチャルホストごとの設定を書く。
割り当てるIPアドレスとポート番号は VirtualHost ディレクティブに書く。
*:80 と *:443 でほとんどの場合十分なはず。
ServerName が書いてあれば、それを見てバーチャルホストとして取り扱ってくれる。
000-default.conf をコピペして ServerName を追加すれば最低でもこれで動く。
追加
ServerName
ディレクトリを変える
DocumentRoot
ディレクトリを変えた方が良いもの
ErrorLog
CustomLog
サイトを有効化する
a2ensite 設定ファイル名
ログのローテートができるようにする。
デフォルトの設定は以下のようになっている。
code:/etc/logrotate.d/apache2
/var/log/apache2/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
prerotate
if -d /etc/logrotate.d/httpd-prerotate ; then
run-parts /etc/logrotate.d/httpd-prerotate
fi
endscript
postrotate
if pgrep -f ^/usr/sbin/apache2 > /dev/null; then
invoke-rc.d apache2 reload 2>&1 | logger -t apache2.logrotate
fi
endscript
}
以下のようにファイルのパスを追加すればよい。
code:/etc/logrotate.d/apache2
/var/log/apache2/*.log
/var/log/apache2/domain1/*.log
/var/log/apache2/domain2/*.log
{
...
https を有効にする。
ssl モジュールを有効にする。
a2enmod ssl
default-ssl.conf を設定ファイルにコピペして、以下
追加
ServerName
ディレクトリなどを変える
DocumentRoot
SSLCertificateFile
SSLCertificateKeyFile
ディレクトリを変えた方が良いもの
ErrorLog
CustomLog
HSTS を有効にする。(常時TLS化、常時SSL化、常時https化。http ではなく、必ず https を使うようにする設定)
rewrite モジュールを有効にする。
headers モジュールを有効にする。
https 側の VirtualHost 設定に以下を追加する。
code:conf
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
http 側の VirtualHost 設定に以下を追加する。
code:conf
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 R,L