Using NGINX as a load balancer for a API

Viewed 163

My goal is to have NGINX act as a load balancer for an API that is on different ports on my local computer. The issue is the API I am using needs to point to a specific location on the server in order to work. In the example below I am using NGINX only as a reverse proxy.

server {
    listen       80;
    server_name  localhost;


    location / {
        proxy_pass http://localhost:8080/api/darkshield/searchContext.mask;

    }

I have a python script that acts as the user and it works no problem. The issue is when I try to create an upstream to have NGINX act as the load balancer for the API.

upstream backend{
    server localhost:8080;
    server localhost:8081;
}

server {
    listen       80;
    server_name  localhost;



    location / {
        proxy_pass http://backend/;

    }

In the upstream when I create the group of servers I can't add the "/api/darkshield/searchContext.mask" to the end of the port number like I could in the first example because NGINX won't run. From what I've seen I can only use an IP and Port Number. Is there a way to add the missing information once a server has been picked from the upstream?

0 Answers
Related