【Apache】ログに不要な情報を記録しないようにする

WordPressを運用しているといろんなアクセスが来ますよね。

日々ログを眺めていると、Rewriteで410を返しているログが記録されていてある意味邪間に思えてきます。

そこで、当サイトで下記のような設定をしています。

 

Rewrite設定

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/sample-page [OR]
RewriteCond %{REQUEST_URI} ^/wordpress [OR]
RewriteCond %{REQUEST_URI} \.env [OR]
RewriteCond %{REQUEST_URI} \.git [OR]
RewriteCond %{REQUEST_URI} ^/cgi-bin [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin/setup-config.php [OR]
RewriteCond %{REQUEST_URI} ^/setup-config.php [OR]
RewriteCond %{REQUEST_URI} ^.*/wlwmanifest.xml [OR]
RewriteCond %{REQUEST_URI} /install.php [OR]
RewriteCond %{REQUEST_URI} ^/sellers.json [OR]
RewriteCond %{REQUEST_URI} ^/geoserver [OR]
RewriteCond %{REQUEST_URI} ^/admin [OR]
RewriteCond %{REQUEST_URI} ^/admin/config.php [OR]
RewriteCond %{REQUEST_URI} ^/lander [OR]
RewriteCond %{REQUEST_URI} ^/_profiler/phpinfo [OR]
RewriteCond %{REQUEST_URI} phpinfo [OR]
RewriteCond %{REQUEST_URI} info.php [OR]
RewriteCond %{REQUEST_URI} ^/merchant [OR]
RewriteCond %{REQUEST_URI} ^/actuator [OR]
RewriteCond %{REQUEST_URI} ^/3ds [OR]
RewriteCond %{REQUEST_URI} ^/server [OR]
RewriteCond %{REQUEST_URI} ^/.vscode [OR]
RewriteCond %{REQUEST_URI} ^/v2/_catalog [OR]
RewriteCond %{REQUEST_URI} ^/ecp/Current [OR]
RewriteCond %{REQUEST_URI} ^/server-status [OR]
RewriteCond %{REQUEST_URI} ^/login.action [OR]
RewriteCond %{REQUEST_URI} ^/_all_dbs [OR]
RewriteCond %{REQUEST_URI} ^/.DS_Store [OR]
RewriteCond %{REQUEST_URI} ^/s/ [OR]
RewriteCond %{REQUEST_URI} ^/config.json [OR]
RewriteCond %{REQUEST_URI} ^/telescope [OR]
RewriteCond %{REQUEST_URI} ^/version [OR]
RewriteCond %{REQUEST_URI} phpunit [OR]
RewriteCond %{REQUEST_METHOD} SSTP_DUPLEX_POST [OR]
RewriteCond %{QUERY_STRING} XDEBUG_SESSION_START
RewriteRule ^.*$ - [NC,R=410,L]

多分脆弱性をスキャンするためにアクセスしていると思うのですが、上記のようなRewrite設定で410 Goneを返すようにしています。

これによりWordPress自体にも余計な負荷をかけずに済みます。

次に上記Rewriteで410を返しているアクセスについては、ログに記録を残さない設定です。

 

不要なアクセスログを残さない設定

SetEnvIf Request_URI .*setup-config\.php nolog
SetEnvIf Request_URI ^/sample-page nolog
SetEnvIf Request_URI ^/wordpress nolog
SetEnvIf Request_URI ^.*\.env nolog
SetEnvIf Request_URI ^.*\.git nolog
SetEnvIf Request_URI ^/cgi-bin nolog
SetEnvIf Request_URI ^.*/wlwmanifest.xml nolog
SetEnvIf Request_URI /install.php nolog
SetEnvIf Request_URI ^/sellers.json nolog
SetEnvIf Request_URI ^/geoserver nolog
SetEnvIf Request_URI ^/admin nolog
SetEnvIf Request_URI ^/admin/.* nolog
SetEnvIf Request_URI ^/lander nolog
SetEnvIf Request_URI ^/_profiler/phpinfo nolog
SetEnvIf Request_URI phpinfo nolog
SetEnvIf Request_URI info.php nolog
SetEnvIf Request_URI ^/merchant nolog
SetEnvIf Request_URI ^/actuator nolog
SetEnvIf Request_URI ^/3ds nolog
SetEnvIf Request_URI ^/server nolog
SetEnvIf Request_URI ^/.vscode nolog
SetEnvIf Request_URI ^/v2/_catalog nolog
SetEnvIf Request_URI ^/ecp/Current nolog
SetEnvIf Request_URI ^/server-status nolog
SetEnvIf Request_URI ^/login.action nolog
SetEnvIf Request_URI ^/_all_dbs nolog
SetEnvIf Request_URI ^/.DS_Store nolog
SetEnvIf Request_URI ^/s/.* nolog
SetEnvIf Request_URI ^/config.json nolog
SetEnvIf Request_URI ^/telescope nolog
SetEnvIf Request_URI ^/version nolog
SetEnvIf Request_URI ^phpunit nolog
SetEnvIf Request_Method SSTP_DUPLEX_POST nolog

CustomLog "|/usr/local/ap/apache/bin/rotatelogs logs/ssl-rgz95.com.access_log.%Y%m%d 86400 540" combined env=!nolog

上記設定を加えることで余計なログが記録されることを防げます。

早速やってみましたが、かなりログが綺麗になりスッキリしました。確認が必要なアクセスログを見分けやすくなり良いことずくめでした。

何かの参考になれば幸いです。

 

 

 

 

 

おすすめの記事