Strip Query String from Nginx Logs

By | January 12, 2018

We have a web application that has a legacy route where people put their API Key as a query string. We want that data to NOT be logged by Nginx. How can we maintain the standard Nginx log format, just without logging the query string data?


Here’s how it’s done:

log_format combined_no_query '$remote_addr - $remote_user [$time_local] '
   '"$request_method $uri" $status $body_bytes_sent '
   '"$http_referer" "$http_user_agent"';

# ...

server {
  # ...
  access_log /var/log/nginx/access.log combined_no_query;
  # ...

Leave a Reply

Your email address will not be published. Required fields are marked *