Created
June 4, 2012 07:57
-
-
Save deltheil/2867074 to your computer and use it in GitHub Desktop.
Hide sensitive GET parameters within nginx access logs thanks to the Lua module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
log_format filt '$remote_addr - $remote_user [$time_local] "$_request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
server { | |
location /login { | |
# `set` is provided by the Rewrite module | |
set $filter "password|secret"; | |
set_by_lua $_request ' | |
local filt = ngx.arg[1] | |
local req = ngx.arg[2] | |
return ngx.re.gsub(req, "((" .. filt .. ")=)[^&]+", "$1-FILTERED-") | |
' $filter $request; | |
access_log logs/access.log filt; | |
# ... | |
} | |
} | |
} |
location /xxx {
#Strip password in access.log
set $temp $request;
if ($temp ~ (.*)password=[^&]*(.*)) {
set $temp $1password=****$2;
}
log_format filter '$remote_addr - $remote_user [$time_local] '
'"$temp" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log logs/access.log filter;
}
Thanks for this alternative!
The above alternative from @Rockes won't work because you can't have log_format
directives inside location
blocks. It can only exist inside http
blocks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://nginx.2469901.n2.nabble.com/Remove-query-parameter-td5187941.html