最近ではNginxを使用することも増えてますが、CentOSでApacheを構築した時に忘れがちながセキュリティ設定のメモ。
今回はCentOS7で。
セキュリティ設定用のファイルを新規で作成
$ vi /etc/httpd/conf.d/security.conf
security.confに以下を記述
#ResponseHeader に含まれるServerの情報を非表示 ServerTokens Prod #エラー画面に表示されるApacheのバージョン情報を非表示 ServerSignature Off #PHPのバージョン情報も非表示 Header unset X-Powered-By #httpoxy 対策 RequestHeader unset Proxy # クリックジャッキング対策 Header append X-Frame-Options SAMEORIGIN # XSS対策 Header set X-XSS-Protection "1; mode=block" Header set X-Content-Type-Options nosniff # XST対策 TraceEnable Off
ディレクトリ一覧を表示させないようにautoindex.confの中を空に
$ cat /dev/null > /etc/httpd/conf.d/autoindex.conf
index.htmlがない場合、ウェルカムページが表示されるので、welcome.confの中を空にして非表示に
$ cat /dev/null > /etc/httpd/conf.d/welcome.conf
PHPのphp.iniにも念のためHTTPヘッダにPHPのバージョンが非表示になるように設定。
expose_php = Off
Apacheの再起動
$ systemctl restart httpd