Apache2.4のvirtual host・認証と負荷1 / 4
設定とvirtual host
ApacheはListenで受けるaddress/port、VirtualHostでその接続に使う設定、ServerName/ServerAliasでhost名等を対応させる。名前ベースでは同じIP/portへ複数hostを置ける。clientのHost等が一致しない場合、そのaddress/portの最初のhostが既定へ関わるため、設定順も扱う。
Listen 80
<VirtualHost *:80>
ServerName www.example.test
DocumentRoot /srv/www/example
ErrorLog /var/log/apache2/example-error.log
CustomLog /var/log/apache2/example-access.log combined
<Directory /srv/www/example>
Options -Indexes
AllowOverride None
Require all granted
</Directory>
Redirect permanent /old https://www.example.test/new
</VirtualHost>
DocumentRootとdirectoryを用意し、Apacheの実行userへ必要な読取り・探索権限を与える。Options -Indexesは一覧生成を抑制する。はfilesystem、はURL空間の条件で、Alias等を使うと対応が単純な文字列一致とは限らない。