首页 > 代码库 > nginx log 敏感信息过滤

nginx log 敏感信息过滤

有时我们会通过url传递一些敏感信息如token等,同时又不希望这些信息被记录在nginx的log(可能会分发给数据处理或解决bug的人)里。

这时需要过滤url.具体方法如下

http{

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for" $request_time‘;

    server{
        listen 80;
        server_name localhost;
        set $filtered_request $request;
        if ($filtered_request ~ (.*)token=[^&]*(.*)) {
            set $filtered_request $1token=******$2;
        }
        access_log  logs/filter.access.log  filter;
    }
}

 

nginx log 敏感信息过滤