Trying to use nginx as load balancer. But I'm getting 502 error

50 Views Asked by At

I have two Linode compute instances that are running on centos7.

  • private_ip: 192.168.150.22, label: load_balancer
  • private_ip: 192.168.150.95, label: app01

I have nginx installed in the load_balancer instance.

nginx.conf:

events {
    worker_connections 1024;
}

http {
    upstream backend {
        server 192.168.150.95:5000;
    }

    server {
        listen 80;
        location / {
            proxy_pass http://backend;
        }
    }
}

In the app01 instance, I have a nodejs web app running on 5000 port. The app is in the /opt/app directory in the app01 server.

I can access the app01's port 5000 by doing curl 192.168.150.95:5000. But when I access the load_balancer instance from a web browser, I get a 502 error page from nginx.

Firewall rules in load_balancer instance:

$ firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 80/tcp 5000/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Firewall rules in app01 instance:

firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 5000/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Error logs in load_balancer instance

tail error.log -n 5
2023/07/15 07:46:35 [crit] 7610#7610: *1 connect() to 192.168.150.95:5000 failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.150.95:5000/favicon.ico", host: "y.y.y.y", referrer: "http://y.y.y.y/"
2023/07/15 07:49:39 [crit] 7610#7610: *4 connect() to 192.168.150.95:5000 failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: , request: "GET /.git/config HTTP/1.1", upstream: "http://192.168.150.95:5000/.git/config", host: "y.y.y.y"
2023/07/15 07:49:39 [crit] 7610#7610: *6 connect() to 192.168.150.95:5000 failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: , request: "GET /.git/config HTTP/1.1", upstream: "http://192.168.150.95:5000/.git/config", host: "y.y.y.y"
2023/07/15 07:49:43 [crit] 7610#7610: *8 connect() to 192.168.150.95:5000 failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: , request: "GET /.git/config HTTP/1.1", upstream: "http://192.168.150.95:5000/.git/config", host: "y.y.y.y"
2023/07/15 07:49:44 [crit] 7610#7610: *10 connect() to 192.168.150.95:5000 failed (13: Permission denied) while connecting to upstream, client: x.x.x.x, server: , request: "GET /.git/config HTTP/1.1", upstream: "http://192.168.150.95:5000/.git/config", host: "y.y.y.y"
1

There are 1 best solutions below

0
Abu Zakaria On

Running this command solved the problem.

setsebool -P httpd_can_network_connect 1