0
votes

I am new to nginx config and I am trying to set up a reverse proxy using nginx and want to use load balancing of nginx to equally distribute the load on the two upstream servers of the upstream custom-domains i.e
server 111.111.111.11; server 222.222.222.22;.

Shouldn't the distribution be round robin by default? I have tried weights, no luck yet. This is what my server config looks like:

upstream custom-domains {
    server 111.111.111.11;
    server 222.222.222.22;
}
upstream cert-auth {
    server 00.000.000.000;
} 
server {
    listen       80;
    server_name  _;

   #access_log  /var/log/nginx/host.access.log  main;

    location / {
        proxy_pass http://custom-domains;
        proxy_http_version   1.1;
        proxy_set_header     Upgrade $http_upgrade;
        proxy_set_header     Connection upgrade;
        proxy_set_header     Host $host;
        proxy_cache_bypass   $http_upgrade;
    }
    location /.well-known/ {
        proxy_pass http://cert-auth;
    }
}

Right now all the load seems to be redirecting to just the first server i.e. 111.111.111.11.

Help is greatly appreciated! Thanks again.

1
unless your second server is down or not reachable, the config you pasted seems fine. And yes, default is round-robin. Can you check the logs on that server, make sure it's responding? Can you manually access it from the nginx server via curl? - Raul
I am getting errors in the error logs of both php-fpm and httpd ERROR: FPM initialization failed - Anmol Singh
httpd error looks like [mpm_worker:error] [pid 20560:tid 140188821104768] AH00286: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting - Anmol Singh
So it means that your second webserver is having issues, and nginx checks detected that. Once a server is marked as unhealthy, nginx will not send requests to it. Fix your second webservers and everything will be good again. - Raul

1 Answers

0
votes

The config you posted is fine and should work in round-robin balance mode.

However, as you mentioned, your second webserver is having issues. Once those are fixed, your requests will be load balanced across both servers.