• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

329
Views
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
about 3 years ago · Santiago Trujillo
1 answers
Answer question

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.

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error