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

203
Views
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 answers
Answer question

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 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!