Skip to content

Trimming ModSecurity audit log noise on a busy cPanel server

How to reduce ModSecurity audit log volume on a busy cPanel host by tuning SecAuditEngine, SecAuditLogParts, and serial-vs-concurrent logging, without losing the events that actually matter.

A busy cPanel server with ModSecurity in SecAuditEngine On mode and the full audit log enabled writes hundreds of megabytes a day of request and response data. Most of it is noise — legitimate requests that match no rule. The default cPanel value is RelevantOnly for exactly this reason; the trap is the operator who flipped it to On while debugging a single issue and never flipped it back.

What’s happening

ModSecurity has three audit modes: Off (no log), On (log every request), and RelevantOnly (log only requests that triggered a rule or returned an error). RelevantOnly is what you want in steady state. SecAuditLogParts controls how much of each transaction is logged — request headers, request body, response headers, response body, and a few internal parts. The body parts are by far the biggest contributors to disk usage.

How to verify

Confirm the current ModSecurity audit config:

grep -r "SecAuditEngine\|SecAuditLogParts\|SecAuditLog " /etc/apache2/conf.d/ /etc/cpanel/ea4/
whmapi1 modsec_get_settings
du -sh /etc/apache2/logs/modsec_audit.log /usr/local/apache/logs/modsec_audit.log 2>/dev/null
wc -l /etc/apache2/logs/modsec_audit.log 2>/dev/null

If SecAuditEngine On is set anywhere (not RelevantOnly), the log is recording every request.

The fix

  1. WHM > ModSecurity Tools > Rules List > scroll to Audit Engine. Set to RelevantOnly. Save.
  2. Set SecAuditLogParts to a sensible subset. The default ABIJDEFHZ includes response bodies (E). On a busy host, drop E — ABIJDFHZ. You lose response body inspection but keep request data and headers, which is what 90% of investigations need.
  3. Switch to concurrent logging if not already. SecAuditLogType Concurrent writes each transaction to its own file under SecAuditLogStorageDir, which makes log rotation trivial and avoids the lock contention of Serial. cPanel defaults to Serial; concurrent is the better choice on a busy host.
  4. Set up a directory cleanup. With concurrent logging, files accumulate. A daily find /var/log/modsec_audit -type f -mtime +14 -delete keeps disk usage bounded.
  5. apachectl -t && apachectl graceful. Watch the log directory grow rate: watch -n 60 'du -sh /var/log/modsec_audit'. It should be substantially lower than before.
  6. If you need to debug a specific request — say a customer reports a block — temporarily enable SecAuditEngine On scoped to that vhost via the Include Editor, capture the audit data, then disable. Do not leave it on globally.

For environments where ModSecurity audit data feeds compliance retention, Stack Harbor configures the log shape against the retention requirement under cPanel/WHM management.