Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda