Skip to content

Instantly share code, notes, and snippets.

@GusAntoniassi
Created August 31, 2018 14:37
Show Gist options
  • Save GusAntoniassi/1004f75b769469c9e5d077e5b7ef6e32 to your computer and use it in GitHub Desktop.
Save GusAntoniassi/1004f75b769469c9e5d077e5b7ef6e32 to your computer and use it in GitHub Desktop.
Apache - Disable access loging for ELB healthchecking and internal dummy connections
# Put this inside your VirtualHost configuration or apache.conf file, where the access log is defined
# If conditions adapted from https://stephane.lesimple.fr/blog/2010-01-28/apache-logical-or-and-conditions-with-setenvif.html
# Initialize variables
SetEnvIf Remote_Addr "^" loopback_ip=0
SetEnvIf Remote_Addr "^" healthcheck_url=0
# Disable apache "internal dummy connections" logging
# (if remote_addr is local and method is "OPTIONS")
SetEnvIf Remote_Addr "^127\.0\.0\.1$" loopback_ip=1
SetEnvIf Remote_Addr "^::1$" loopback_ip=1
SetEnvIf Request_Method "OPTIONS" dummy_connection=1
SetEnvIf loopback_ip 0 !dummy_connection
# Disable ELB healthcheck requests
# (if URL is "/elbhealthcheck" and user-agent starts with "ELB-HealthChecker")
SetEnvIf Request_URI "^/elbhealthcheck$" healthcheck_url=1
SetEnvIf User-Agent "^ELB-HealthChecker" is_healthchecker=1
SetEnvIf healthcheck_url 0 !is_healthchecker
# Set conditions into dontlog variable
SetEnvIf dummy_connection 1 dontlog
SetEnvIf is_healthchecker 1 dontlog
CustomLog /var/log/apache2/access.log combined env=!dontlog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment