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

161
Views
Nginx regex to exclude certain paths

I am trying to exclude some paths in my nginx proxypass and want everything else to go to my proxypass.

i.e I dont want to give proxy_pass to any url which starts with 'tiny' or 'static', but want everythign else to go to my proxypass location.

and I am using following regex to achieve this:

~ ^((?!tiny|static).)*$

But I always get 404 error. If I navigate to following url in browser

localhost:8080/xyz

I want it to go to

localhost:8000/api/tiny/records/xyz

Can someone please help me in pointing out what is the issue ?

Here is my full nginx conf file:-

server {
        listen       8080;
        server_name  localhost;
        location   ~ ^((?!tiny|static).)*$ {
            proxy_pass  http://localhost:8000/api/tiny/records/$1;
        }
        location   / {
            proxy_pass  http://localhost:8000;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

Thanks a lot.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are missing a / and have the * in the wrong place. The regular expression should be:

^(/(?!tiny|static).*)$

But you do not need to use a regular expression with a negative lookahead assertion. Instead, place a normal regular expression on the other location block.

For example:

location / {
    proxy_pass  http://localhost:8000/api/tiny/records/;
}
location ~ ^/(tiny|static) {
    proxy_pass  http://localhost:8000;
}
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!