问题:
以下是当前配置:
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.1
GET /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;
}
相关文章