SSL化してしばらく経ちますが、標準状態のアクセスログ ssl_access_log では、リファラーやらUser Agent やら記録されず、不便に感じるシーンがあったので設定変更を行いました。
通常のアクセスログと同じフォーマットでSSLのアクセスも記録するように変更します。これで各種クローラーなどからのアクセスの判断もしやすくなりますね。
目次
アクセスログフォーマットの変更
SSL化しているので設定については、/etc/httpd/conf.d/ssl.confを編集します。
環境は変更なく、CentOS 7(現時点では 7.6.1810)です。
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
TransferLog logs/ssl_access_log
LogLevel warn
ErrorLogディレクティブの次行にLogFormatディレクティブでログフォーマットを指定してやります。
これで、リファラーとUser Agentが追加され、非SSL環境でのアクセスと同じフォーマットで記録されるようになります。
設定後、Apacheを再起動して問題なければ設定完了です。
$ sudo systemctl restart httpd.service
$ sudo systemctl status httpd.service
* httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2019-06-05 23:56:48 JST; 15s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 24921 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 24926 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
|-24926 /usr/sbin/httpd -DFOREGROUND
|-24927 /usr/sbin/httpd -DFOREGROUND
|-24928 /usr/sbin/httpd -DFOREGROUND
|-24929 /usr/sbin/httpd -DFOREGROUND
|-24930 /usr/sbin/httpd -DFOREGROUND
|-24931 /usr/sbin/httpd -DFOREGROUND
|-24932 /usr/sbin/httpd -DFOREGROUND
|-24934 /usr/sbin/httpd -DFOREGROUND
|-24935 /usr/sbin/httpd -DFOREGROUND
|-24942 /usr/sbin/httpd -DFOREGROUND
|-24943 /usr/sbin/httpd -DFOREGROUND
|-24944 /usr/sbin/httpd -DFOREGROUND
`-24945 /usr/sbin/httpd -DFOREGROUND
Jun 05 23:56:48 www.u-1.net systemd[1]: Starting The Apache HTTP Server...
Jun 05 23:56:48 www.u-1.net systemd[1]: Started The Apache HTTP Server.


コメント