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

321
Views
Nginx reverse proxy pathname clash

I am currently running two webservers on the same machine, one using Django through Gunicorn, which is my original site, the other which acts as the online shop using the same domain, this one using Nestjs (Nodejs). Both servers have an /admin path with the original being at example.com/admin and the other I am wanting to be at example.com/store/admin. However whenever I enter the second URL into my browser (i.e example.com/store/admin) it returns the other admin page, example.com/admin (without the /store prefix). Here is the config snippet I believe needs reworking:

server {
        server_name example.com www.example.com;

        location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
        }
        location /store {
                proxy_pass http://127.0.0.1:3000/;
        }
        location = /store/admin {
                proxy_pass http://127.0.0.1:3000/admin/;
        }
    ...
}

I have tried a fair few combinations of the /store and /store/admin location blocks but just can't seem to get it to direct me to the store's server admin site. It works on my local development machine when testing using the nodejs server. Going to http://example.com/store returns what I expect to see from the Nestjs server.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The docs states that:

... To find location matching a given request, nginx first checks locations defined using the prefix strings (prefix locations). Among them, the location with the longest matching prefix is selected and remembered. ...

So you need only two location blocks:

The first :

location / {
  include proxy_params;
  proxy_pass http://unix:/run/gunicorn.sock;
}

And the other with the rewrite:

location /store {
  rewrite ^/store(.*) $1 break;
  proxy_pass http://127.0.0.1:3000;
}

This means it will rewrite every URL starts with /store and remove it from the URL before passing to the upstream. and this also includes the /admin, since it is the same.

Also note there is no suffix / at the end of the proxy_pass - which instruct NGINX to take the user supplied URI.

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!