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

325
Views
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 answers
Answer question

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