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

202
Visualizações
Nginx Strip URL Parameters

I want to strip url params before send it to proxy_pass

For visitor request url: => https://example.com/?wanted1=aaa&unwanted1=bbb&unwanted2=ccc&wanted2=ddd

Then it strip all the unwanted params to: => https://example.com/?wanted1=aaa&wanted2=ddd

My current way is like this:

if ($args ~ ^(.*)&(?:unwanted1|unwanted2)=[^&]*(&.*)?$ ) {
    set $args $1$2;
}

But It only remove 1 param and never do recursion. How to solve this? I want to modify the $args.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you want recursion, you can use a rewrite...last from within a location block. Nginx will only tolerate a small number of recursions (possibly ten iterations) before generating an internal server error.

For example:

location / {
    if ($args ~ ^(?<prefix>.*)&(?:unwanted1|unwanted2)=[^&]*(?<suffix>&.*)?$ ) {
        rewrite ^ $uri?$prefix$suffix? last;
    }
    ...
}

Note that you need to use named captures as the numbered captures are reset when the rewrite statement is evaluated.

Note that rewrite requires a trailing ? to prevent the existing arguments being appended to the rewritten URI. See this document for details.

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