Table of Contents

Apache logging in JSON format to syslog server

JSON

Standard Apache log:-

192.168.1.123 - - [22/Dec/2023:09:00:00 +0000] "GET /birthday.html HTTP/1.1" 404 448 "-" "spoof_user_agent"

This is not a structured format easy to search through or combine with other data in a SIEM.

Add a custom log format in /etc/apache2/apache2.conf file:-

LogFormat section:-

LogFormat "{ \"time\":\"%t\", \"remoteIP\":\"%a\", \"host\":\"%V\", \"request\":\"%U\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"userAgent\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\" }" json_logs

Edit the website conf file:- /etc/apache2/sites-available/mysite.conf

and add

CustomLog ${APACHE_LOG_DIR}/json_access.log json_logs

Syslog

Apache server config

Add custom log line for syslog:-

CustomLog “|/usr/bin/logger -t httpd -p <facility>.<priority>” json_logs

Syslog server config

<facility>.<priority> <TAB><TAB>@<host>