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

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

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