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

324
Vistas
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 Respuestas
Responde la pregunta

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