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

234
Views
Nginx: redirect location based on multiple args

I have an nginx location redirect set up to redirect /my_route to a coming soon page, but allow /my_route?db=preview to pass through to the proxy server.

location /my_route {
  if ($arg_db != "preview") {
    rewrite ^ /coming-soon/ last;
  }
  <other location config for when db == preview>
}

I want to add an additional layer of complexity, to support multiple languages for the coming soon page.

Config that breaks nginx, but give you the idea:

location /my_route {
  if ($arg_db != "preview") {
    if ($arg_lang == "es") {
      rewrite ^ /coming-soon/index_es.html last;
    }
    rewrite ^ /coming-soon/ last;
  }
  <other location config for when db == preview>
}

I know that if is evil, so I'm happy to move away from using if, if that's what is needed, but I don't know which direction to look. I just know nginx doesn't support && statements, or nested if statements.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could use a map to eliminate the inner if block.

For example:

map $arg_lang $mylang {
    default   /;
    es        /index_es.html;
}
server {
    ...
    rewrite ^ /coming_soon$mylang last;
    ...
}

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!