Nginx Config :- Unable to resolve host rabbitmq-2A

145 Views Asked by At

I have nginx configuration to make for rabbitmq cluster whcih has got 3 containers running inside it like rabbitmq-2A, rabbitmq-2B And rabbitmq-2C. (So the host names are confugured in docker compose like rabbitm-2A) but nginx host resolves hostnames only in lower case leter (rabbitmq-2a).

So, I can't rename host because messages are already in queue (don;t want to loose existing messages)

Docker compose file docker-compose-rabbitmq.yml

version: "3.2"

services:
  rabbitmq-2A:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2A

  rabbitmq-2B:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2B

  rabbitmq-2C:
    image: rabbitmq:3-management-alpine
    hostname: rabbitmq-2C

metricsTestA{
set $rabbitmqtest http://rabbitmq-2A;
proxy_pass $rabbitmqtest 
}

This doesn't resolve as nginx tries to resolve it like rabbitmq-2a (which obviosuly) is not a host name

Also, I have tried setting upstream

upstream backends {
    least_conn;

    server backends.example.com:8080 max_fails=3;
}

server {
    location / {
        proxy_pass http://backends;
    }
}

https://www.nginx.com/blog/dns-service-discovery-nginx-plus/ Does anyone know how to get pass this?

1

There are 1 best solutions below

2
On

DNS is case insensitive (RFC 4343), so this not a problem.

I guess more, that the hostnames are not correct.
Here are some hints:

  • Is your nginx in the same namespace?
    • When not, then you need the FQDN instead of simple name. Have a look at the kubernetes-config.
  • Is nginx using the right DNS-server? Can it resolve other services?

Edit

With your latest comment, I can imagine what the problem is.

I guess that you have a StatefulSet?
Then your hostname lookes weird. It should be something like rabbitmq-2A-1 or rabbitmq-1.

StatfulSets have special behaviour according to their hostnames. Related docs: StatefulSets