0

I'm trying to create a proxy in front of a swarm cluster.

This proxy is inside of another swarm cluster, to provide HA.

This is the current structure:

  1. Proxy cluster (ip range 192.168.98.100 ~ 192.168.98.102)
    • proxy-manager1;
    • proxy-worker1;
    • proxy-worker2;
  2. App cluster (ip range 192.168.99.100 ~ 192.168.99.107)
    • app-manager1;
    • app-manager2;
    • app-manager3;
    • app-worker1;
    • app-worker2;
    • app-worker3;
    • app-worker4;
    • app-worker5;

When I configure nginx with the app-manager's IP address, the proxy redirection works good.

But when I configure nginx with the app-manager's hostname or DNS, the proxy service does not find the server to redirect.

This is the working config file:

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    upstream app {
        server 192.168.99.100:8080;
        server 192.168.99.101:8080;
        server 192.168.99.102:8080;
    }
    server {
        listen 80;
        location / {
            proxy_pass http://app;
        }
    }
}

Is that a good practice? Or maybe I'm doing wrong?

DTodt
  • 380
  • 6
  • 19

1 Answers1

0

You have to make sure that nginx can resolve the hostnames to ip addresses. Check this out for more information: https://www.nginx.com/blog/dns-service-discovery-nginx-plus/

Check how nginx is resolving the hostnames or check the hosts files on the nginx servers.

On a side note, I sometimes will run this for the local dns https://cr.yp.to/djbdns.html and then makes sure that all the nginx servers use that dns service running on a server. It is easier to configure djbdns than to keep all the host files updated.

Ray Hunter
  • 15,137
  • 5
  • 53
  • 51