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

423
Vistas
nginx location regex for multiple paths but invalid
    location ^~/images/ {
        root /mnt/disha;
    }
    location ^~/pdf/ {
        root /mnt/disha;
    }
    location ^~/contact/ {
        root /mnt/disha;
    }
    location ^~ /excel {
        root /mnt/disha;
    }

How can I combine these 4 into 1 location?

I tried this:

location ~ ^/(images|pdf|contact|excel)/ {
    root /mnt/disha;
}

It worked fine with 4 location, then nginx comes 404 Not Found once combining with 1.

I also tried location ~* ^/(images|pdf|contact|excel).

all methods I tried is invalid, what should I do?

here is my entire server conf:

server{
    listen 80;
    listen 443 ssl;
    server_name erp.xxx.com;
    index index.html;
    location ~ ^/(images|pdf|contact|excel)/ {
        root /mnt/disha;
    }
    location ^~/{
        root /mnt/disha/erp;
    }
    ssl_certificate /etc/xxx/xxx.pem;
    ssl_certificate_key /etc/xxx/xxx.key;
    ssl_ciphers ECDHE-RSA-AES128-GCM- 
    SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
}

the 404 request i tested:

wget http://erp.xxx.com/excel/export_outbound_stock_20200321150255.xls
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The ^~ modifier causes a matching prefix location to take precedence over all regular expression location blocks.

The location ^~ / { ... } effectively disables any regular expression location.

To change your four prefix location blocks into a single regular expression location block, you must also remove the ^~ modifier from the final location block.

For example:

root /mnt/disha/erp;

location / {
}

location ~* ^/(images|pdf|contact|excel)/ {
    root /mnt/disha;
}

In fact, the location / block can be omitted if it is empty, as the root statement can be placed in the server block context.

See this document for details.

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