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

328
Visualizações
Compose URL address on the location with the server IP address using upstream on Nginx configuration

I have this situation where a have lots of API´s running on different machines on different ports using Tomcat. I can create the upstream with those IP addresses but how to add the other part of the URL to the upstream when setting the proxy_pass?

The upstream:

upstream login_api_stream {
   least_conn; 
   server 10.2.54.8:8185;
   server 10.2.54.8:8285;
   server 10.2.54.8:8385;
   server 10.2.54.9:8085 backup;
}

Then I create the location inside http:

location /login-api/ {
    add_header X-Real-IP $remote_addr;
    add_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header X-Forwarded-Proto $http_x_forwarded_proto;
    # I have to add "login-api/auth" on the upstream
    proxy_pass http://login_api_stream/login-api/auth;
}

As you can see I must add this "login-api/auth" because the real URL address on the redirected address is: http://10.2.54.8:8185/login-api/auth

How can I do that?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

After some digging I ended up with this solution:

The upstream (important to notice, you cannot use this sign _ in the name of the upstream):

upstream newlogin {
   least_conn; 
   server 10.2.54.8:8085;
   server 10.2.54.8:8285;
   server 10.2.54.8:8185;
   server 10.2.54.9:8085 backup;
}

The location:

location ~ ^/login-api/auth/ {
    add_header Host $host;
    add_header X-Real-IP $remote_addr;
    add_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_pass http://newlogin$uri$is_args$args;
}

And then in browser I call:

http://MyNginxDomain/login-api/auth/
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