Apache2インストール

takasan@web1:~ $ sudo apt-get -y install apache2

バージョン確認
takasan@web1:~ $ apachectl -v
Server version: Apache/2.4.57 (Debian)
Server built: 2023-04-13T03:26:51

module_headersの活性化…セキュリティ対策

HTTP のリクエストヘッダと応答ヘッダを制御し、 追加・変更・削除します。

takasan@web1:~ $ sudo a2enmod headers
Enabling module headers.
To activate the new configuration, you need to run:
systemctl restart apache2

rewriteの活性化

アクセスのあったURLを、正規表現で書き換えてから処理する機能です。
書き換えで対処できることが一杯あるので有効にします。

takasan@web1:~ $ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2

インストール直後のHTTPヘッダの確認

takasan@web1:~ $ curl -v http://localhost | more

<<表示省略>>

セキュアな設定

takasan@web1:~ $ sudo cp /etc/apache2/conf-enabled/security.conf /etc/apache2/conf-enabled/security.conf.org
takasan@web1:~ $ sudo nano /etc/apache2/conf-enabled/security.conf

<<詳細省略>>

Apache2のサーバを再起動

takasan@web1:~ $ sudo systemctl restart apache2.service

セキュリティ設定後のHTTPヘッダの確認

takasan@web1:~ $ curl -v http://localhost | more

変更になった部分は、
*< Server: Apache <=バージョン情報が出力されていません。

*< Vary: Accept-Encoding
< X-Content-Type-Options: nosniff <=追記された
< X-Frame-Options: sameorigin <=追記された
< X-XSS-Protection: 1; mode=block <=追記された
< Content-Type: text/html