从nginx上的访问日志中隐藏获取参数

我想启用访问日志以查看有关我们服务的统计信息,我遇到的问题是访问日志格式的$request,保存所有GET参数(这是有意义的,因为它是请求的一部分)

但我想隐藏这些信息,所以不要在日志上看到这个:

98.207.174.147 - - [26/Apr/2014:23:59:09 +0000] "GET /v1/api.json?parameter1=value1&paramter2=value2" HTTP/1.1" 200 13449 "-" "httperf/0.9.0"

我想看看

98.207.174.147 - - [26/Apr/2014:23:59:09 +0000] "GET /v1/api.json" HTTP/1.1" 200 13449 "-" "httperf/0.9.0"

最佳答案
您可以使用ngx_http_log_module的log_format指令.

例如,此格式只显示没有任何查询字符串的uri:

http {
       log_format combined_no_query '$remote_addr - $remote_user [$time_local] '
           '"$uri" $status $body_bytes_sent '
           '"$http_referer" "$http_user_agent"';
       //other configs ...
     }

 server {
       access_log /var/log/nginx/access.log combined_no_query
       //... 
      }

注意$uri变量,它仅用于记录没有任何查询字符串的uri.

doc for log_format指令:http://nginx.org/en/docs/http/ngx_http_log_module.html

更多变量:http://nginx.org/en/docs/http/ngx_http_core_module.html#var_uri

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。