1、特定条件写日志:

参照:

https://stackoverflow.com/questions/19011719/how-to-write-only-logs-with-200-status

http://nginx.org/en/docs/http/ngx_http_map_module.html

http {

    map $status $normal {
        ~^2  1;
        default 0;
    }
    map $status $abnormal {
        ~^2  0;
        default 1;
    }
    map $remote_addr $islocal {
        ~^127  1;
        default 0;
    }

    server {

        access_log logs/access.log combined if=$normal;
        access_log logs/access_abnormal.log combined if=$abnormal;
        access_log logs/access_local.log combined if=$islocal;

    }  
}

 

2、特定条件不写日志:

参照:https://github.com/cfsego/ngx_log_if/

此处需要自行编译nginx加入ngx_log_if模块