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

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

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