In Apache's default configuration, if you don't explicitly define ErrorLog and CustomLog directives within a VirtualHost block, the server will automatically use the main server's error and access logs defined in the global configuration. This can lead to cluttered log files when you want to completely suppress logging for specific virtual hosts.
To completely disable logging for a particular virtual host, you need to explicitly configure both error and access logs to discard the output. Here's how to implement this:
<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/example # Disable error logging ErrorLog /dev/null # Disable access logging CustomLog /dev/null common # Alternative for access log (works on Windows too) # CustomLog "|bin/rotatelogs /dev/null 5M" common # Rest of your configuration... </VirtualHost>
The solution above uses Unix/Linux specific /dev/null
. For Windows systems, you can use:
ErrorLog "nul" CustomLog "nul" common
If you want more control rather than completely disabling logs, consider conditional logging based on environment variables:
<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/example SetEnvIf Request_URI "^" dontlog CustomLog logs/access_log common env=!dontlog </VirtualHost>
After making these changes, always verify your configuration:
apachectl configtest systemctl restart apache2
While disabling logs can be useful for certain hosts, be aware that this:
- Removes visibility into potential security issues
- Makes troubleshooting more difficult
- Should only be done for non-critical virtual hosts
Apache's default configuration automatically logs all access and errors to the main log files when no specific logging directives are defined within a VirtualHost block. This behavior can create unnecessary log clutter when you want to completely disable logging for a particular virtual host.
To completely suppress both access and error logging for a specific virtual host, add these directives inside your VirtualHost configuration:
ServerName example.com DocumentRoot /var/www/example # Disable access log CustomLog /dev/null combined # Alternative for Apache 2.4+ CustomLog "|/bin/cat" combined # Disable error log ErrorLog /dev/null # Alternative for better performance ErrorLog "|/bin/cat" # For Apache 2.4+, you can also use ErrorLog "off"
While sending logs to /dev/null
works, using pipe to /bin/cat
(Apache 2.4+) is more efficient as it avoids filesystem operations. The most modern approach is simply using ErrorLog "off"
directive in Apache 2.4+.
If you need to maintain some logging while reducing verbosity:
ServerName example.com # Minimal error logging (only critical errors) LogLevel crit ErrorLog /var/log/apache2/example-error.log # Access log with reduced information CustomLog /var/log/apache2/example-access.log "%h %l %u %t \"%r\" %>s %b"
After making these changes:
- Test configuration with
apachectl configtest
- Reload Apache:
systemctl reload apache2
- Verify no new entries appear in default logs for this host