在Nginx中,从记录中排除特定的查询参数?

分享于 

2分钟阅读

互联网

  繁體

问题:

以下是当前配置:


log_format main '$remote_addr - $remote_user [$time_local] $host "$request" '


 '$status $body_bytes_sent $request_time "$http_referer" '


 '"$http_user_agent" "$http_x_forwarded_for"';



我想要GET /index.html?latitude=43.4321&otherkey=value HTTP/1.1GET /index.html?latitude=******&otherkey=value HTTP/1.1


答案1:

GET /index.html?key=latitude&otherkey=value HTTP/1.1 变成GET /index.html?key=***&otherkey=value HTTP/1.1

下面是代码:


log_format main '$remote_addr - $remote_user [$time_local] $host "$customrequest" '


 '$status $body_bytes_sent $request_time "$http_referer" '


 '"$http_user_agent" "$http_x_forwarded_for"';


map $request $customrequest {


 ~^(.*)(latitude)(.*)$ "$1***$3";


 default $request;


}



你可以添加多个关键字,如下所示:~^(.*)(latitude|dell|inspiron)(.*)$

在注释中指定之后,需要修改正规表达式:GET /index.html?latitude=5570&otherkey=value HTTP/1.1 变成GET /index.html?latitude=***&otherkey=value HTTP/1.1


map $request $customrequest {


 ~^(.*)([?&]latitude=)([^&]*)(.*)$ "$1$2***$4";


 default $request;


}





PAR  log  spec  Nginx  parameter  不包含  
相关文章