Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

414
Views
Strip single GET query parameter from Nginx access log and keep all the others

I have seen similar questions but not specifically this, i don't want to stop logging urls with a parameter, i want to log them without it.

example initial url:

example.com/dir/file.php?important=1&ignore=random&others=yes

How it needs to be logged as:

example.com/dir/file.php?important=1&others=yes

Basically i want to filter out the 'ignore' parameter while keeping the rest intact, if present.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

you will need to create a custom log format, including a custom variable, and not including the $request variable. For example:

log_format main  '$remote_addr - $remote_user [$time_local] "$custom_request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log main;

I'm adding the variable "$custom_request", that doesn't exist. So you need to create it first. And you can create it based on the $request, using regex to remove what you don't want.

set $custom_request $request;
if ($request_uri ~ "([^\?]*)\?(.*)ignore=([^&]*)&?(.*)") {
    set $original_path $1; 
    set $args_before $2; 
    set $unwanted $3; 
    set $args_after $4; 
    set $args ""; 

    set $custom_request "${original_path}?${args_before}${args_after}";
}
over 4 years ago · Santiago Trujillo Report

0

Update to Carlos's answer: Same:

log_format main  '$remote_addr - $remote_user [$time_local] "$custom_request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log main;
Different:
set $custom_request "";
if ($request_uri ~ "([^\?]*)\?(.*)auth=([^&]*)&?(.*)") {
    set $original_path $1;
    set $before $2;
    set $unwanted $3;
    set $after $4;
    set $custom_request "${request_method} ${original_path}?${before}auth=*****${after} $server_protocol";
}

Note that the set and if directives must be put in the server block. I took out the line set $args ""; because it wiped the $args variable clean for no reason and impacted more than the logs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!