1

I have experience the problem in nginx load balancing configuration. the load balancing server doesn't want to forward into any backend server.

I set the server configuration as below:

Hostname                ip_address      role
nginx-node1.phann.net   172.17.45.103   nginx webserver
nginx-node2.phann.net   172.17.45.107   nginx webserver
nginx-node3.phann.net   172.17.45.108   nginx webserver
phann.net               172.17.45.113   load balancer

my load balancer configuration in "/etc/nginx/conf.d/load-balancer.conf", using vhost, written as below:

upstream website  {
   server nginx-node1.phann.net;
   server nginx-node2.phann.net;
   server nginx-node3.phann.net;
}
server {
   listen 80; # Listen on the external interface
   location / {
        proxy_pass  http://website;
   }
}

For addition I also have php enable in every server. my configuration is fine and nothing error.

as alternative configuration, I also tried by replacing hostname with IP addresses.

upstream website  {
   server  172.17.45.103;
   server  172.17.45.107;
   server  172.17.45.108;
}
server {
   listen 80; # Listen on the external interface
   location / {
        proxy_pass  http://website;
   }
}

Finally when I tested the load balancing server, it always show the default web page of nginx, it doesn't forward to node1 untill node3. but I've checked that everything is appropriate. I'm wondering in which part I am lacking or making a mistake in the configuration. I've done a lot of research but still can't figure out why "upstream" is not working.

I'm using tutorial from: http://www.itadminstrator.com/2017/07/how-to-configure-nginx-load-balancer-on.html?showComment=1516785023396

closed as off-topic by Kusalananda, Anthony Geoghegan, Jeff Schaller, mdpc, Satō Katsura Mar 6 '18 at 9:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Kusalananda, Anthony Geoghegan, Jeff Schaller, mdpc, Satō Katsura
If this question can be reworded to fit the rules in the help center, please edit the question.

  • The config seems ok. Are the DNS names of the http servers already defined in DNS? – Rui F Ribeiro Jan 25 '18 at 10:48
  • @RuiFRibeiro, I already define it in /etc/hosts in every server. – Phann Jan 25 '18 at 10:53
  • It seems that in your setup/with NGinx /etc/hosts is not being enough, I suspect. You can make a quick test, replace those names by IP addresses if not using vhosts. – Rui F Ribeiro Jan 25 '18 at 10:56
  • @RuiFRibeiro, I'm running curl nginx-node1.phann.net command from load balancer it works fine and show the result of webpage. it also works fine for other server node2 and node3 – Phann Jan 25 '18 at 10:59
  • 4
    @Phann Welcome to Unix & Linux! Instead of editing the question to include the solution, you should post the solution as an actual answer. That way, it's easier to distinguish the solution from the problem and more helpful for others with similar issues. I'd advise taking the tour to get an overview of how the Stack Exchange sites work and reading up on How to Ask and How to Answer. – Anthony Geoghegan Mar 5 '18 at 10:51
0

The NGinx load balancer configuration is ok.

The problem is you not having you names in DNS and NGinx, or at least proxy_pass by default not getting names from /etc/hosts per the DNS resolver as other Linux apps.

See proxy_pass does not resolve DNS using /etc/hosts

If you are not dealing with vhosts, one temporary solution easier than proposed in that link is in the NGinx configuration, using IP addresses instead of FQDNs.

  • 2
    I'v already done replacing the hostname by IP addresses, but it still doesn't work. I'v also done adding http{..} in the configuration,and when I tested it using nginx -t it shows failed. – Phann Jan 25 '18 at 11:16
  • Sorry, at the moment lack of further ideas and busy here. – Rui F Ribeiro Jan 25 '18 at 11:21
  • ok, thank you very much for your suggestion.. I'll try to use vhosts first.. – Phann Jan 25 '18 at 11:25
  • vhosts seems doesn't work either for this configuration – Phann Jan 30 '18 at 10:01
0

Extracted from the Question because this is an answer:

Then, I have found the problem. Because I left /etc/nginx/nginx.conf by default, there are double definition of server {..} script.

it turns out the server {..} script in /etc/nginx/nginx.conf, must be deleted or commented, so the declaration of server {..} script in /etc/nginx/conf.d/load-balancer.conf can run.

Not the answer you're looking for? Browse other questions tagged or ask your own question.