How to Customize Apache Log Format for Fail2ban

Customize apache2 other_vhosts_access.log format so fail2ban can use it.

sudo vi /etc/apache2/apache2.conf

On line 255 insert

LogFormat “%t %v:%p %h %l %u \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” fail2ban

Comment out the following line

#LogFormat “%v:%p %h %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” vhost_combined

sudo vi /etc/apache2/conf.d/other-vhosts-access-log

change the end of the line (or duplicate and comment out) as follows

#CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined
CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log fail2ban

sudo service apache2 restart

You may also like...