Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda