Home > Mobile >  configure NGINX as a simple 2 ARM load balancer
configure NGINX as a simple 2 ARM load balancer

Time:10-19

I would like to configure NGINX as a simple 2 ARM load balancer. This is the target scenario:

enter image description here

I have tried this configuration:

 http {
  upstream backend1 {
    server 192.168.1.3;
    server 192.168.1.2;
  }

  server {
    listen 80;

    location / {
      proxy_pass http://backend1;
    }
  }
}

but it is not working. What am I doing wrong?

CodePudding user response:

http block redefined in default.conf, you could just keep server block in default.conf and move upstream to http block defined in /etc/nginx/nginx.conf

  1. Edit /etc/nginx/site-enabled/default.conf, just keep the server block
server {
    listen 80;

    location / {
      proxy_pass http://backend1;
    }
}
  1. Edit /etc/nginx/nginx.conf, insert your upstream configure
http {
   ...

   // insert upstream before the following two `include` commands
   upstream backend1 {
    server 192.168.1.3;
    server 192.168.1.2;
   }
   
   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/sites-enabled/*;
}
  1. Restart nginx systemctl restart nginx to make your changes take effect.
  • Related