remote_addr 의 주소에 따라서 log 여부를 설정하는 방법을 이용했다.
http 블럭 내에서 map을 이용해 remote_addr에 따른 그룹을 지정한다.
http {
map $remote_addr $log_true {
default yes;
192.168.88.199 no;
192.168.88.162 no;
211.48.203.66 no;
}
}
다음은 server 블록에서 다음과 같이 지정한다.
server {
location / {
if ($log_true = 'no') {
access_log off;
}
}
}
이게 사실 제대로 동작하지 않았다. 그래서 좀 더 시도해 보았다. http 블럭에서 다음과 같이 설정한다.
map $remote_addr $log_true {
default 1;
192.168.88.154 0;
192.168.88.180 0;
192.168.88.162 0;
192.168.88.199 0;
}
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
access_log /var/log/nginx/access.log compression;
server 블럭에서 다음과 같이 해준다.
access_log /var/log/nginx/access.log compression if=$log_true;