Exclude a specific query parameter from being logged in Nginx?
GET /index.html?key=latitude&otherkey=value HTTP/1.1
becomes
GET /index.html?key=***&otherkey=value HTTP/1.1
Here's the code:
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;
}
You can add multiple keywords like this: ~^(.*)(latitude|dell|inspiron)(.*)$
Edit:
After specification in the comment the regex needs to be modified:GET /index.html?latitude=5570&otherkey=value HTTP/1.1
becomesGET /index.html?latitude=***&otherkey=value HTTP/1.1
map $request $customrequest {
~^(.*)([\?&]latitude=)([^&]*)(.*)$ "$1$2***$4";
default $request;
}