Skip to content

Instantly share code, notes, and snippets.

@bsstokes
Created June 10, 2013 13:43
Show Gist options
  • Save bsstokes/5748792 to your computer and use it in GitHub Desktop.
Save bsstokes/5748792 to your computer and use it in GitHub Desktop.
Filter the password from a request in the nginx access log.
log_format filtered_log '$remote_addr - $http_host - $remote_user [$time_local] {$request_time} {$upstream_response_time} $upstream_addr'
'"$filtered_request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
server {
root /home/ubuntu/password_test/www;
index index.html index.htm;
server_name password_test;
location / {
try_files $uri $uri/ /index.html;
#Strip password in access.log
set $filtered_request $request;
if ($filtered_request ~* (.*)(password)=[^&]*(.*)) {
set $filtered_request $1$2=[FILTERED]$3;
}
access_log /home/ubuntu/password_test/logs/access.log filtered_log;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment