Overview
This is a memo on how to turn off logging when the User-Agent ($http_user_agent) of an ELB health check is ELB-HealthChecker.
1 2 3 4 5 6 7 8 9
| http { ... map $http_user_agent $loggable { ~ELB-HealthChecker 0; default 1; }
access_log /var/log/nginx/access.log ltsv if=$loggable; }
|
You can specify a condition with the if parameter of access_log to toggle access log output on and off.
Configuration Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| http { ... # access log を ltsv 形式にする log_format ltsv 'domain:$host\t' 'host:$remote_addr\t' 'user:$remote_user\t' 'time:$time_local\t' 'method:$request_method\t' 'path:$request_uri\t' 'protocol:$server_protocol\t' 'status:$status\t' 'size:$body_bytes_sent\t' 'referer:$http_referer\t' 'agent:$http_user_agent\t' 'response_time:$request_time\t' 'cookie:$http_cookie\t' 'set_cookie:$sent_http_set_cookie\t' 'upstream_addr:$upstream_addr\t' 'upstream_cache_status:$upstream_cache_status\t' 'upstream_response_time:$upstream_response_time';
map $http_user_agent $loggable { ~ELB-HealthChecker 0; default 1; }
access_log /var/log/nginx/access.log ltsv if=$loggable;
include /etc/nginx/conf/conf.d/*.conf; }
|
1 2 3 4 5 6 7 8 9 10
| server { listen 80; listen [::]:80;
# ELB のヘルスチェッカーの場合、 200 を返す if ($http_user_agent ~* ELB-HealthChecker) { return 200; } ... }
|
That’s all.
I hope this helps.