# Cannot connect to RabbitMQ using Let'sEncrypt

**URL:** <https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772>\
**Category:** Traefik v2\
**Tags:** tcp\
**Created:** [September 7, 2023, 1:05pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772 "2023-09-07T13:05:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mscrocdile](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mscrocdile](https://community.traefik.io/u/mscrocdile)\
**Post date:** [September 7, 2023, 1:05pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/1 "2023-09-07T13:05:13Z")

</div>

Hi, what's wrong in this configuration.  
My goal is to connect to TCP port of RabbitMQ with TLS using Let's Encrypt.

```auto
http:
   routers:
     toTest:
       rule: "Host(`my.example.com`)" # this works
       service: rabbitmqweb
       tls:
         certResolver: letsencrypt

   services:
     rabbitmqweb:
       loadBalancer:
         servers:
           - url: "http://rabbitmq:15672"

 tcp:
   routers:
     to-rabbitmq:
       entryPoints:
         - "rabbitmq"
       rule: "HostSNI(`my1.example.com`)" #this doesn't work
       service: rabbitmq
       tls:
         certResolver: letsencrypt

   services:
     rabbitmq:
       loadBalancer:
         servers:
           - address: "rabbitmq:5672"

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 7, 2023, 6:17pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/2 "2023-09-07T18:17:03Z")

</div>

Why do you think it is wrong? Did you receive an error message? Care to tell us?

Share your full Traefik static and dynamic config, and `docker-compose.yml` if used.

---

<div class="post-metadata">

**Author:** ![mscrocdile](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mscrocdile](https://community.traefik.io/u/mscrocdile)\
**Post date:** [September 8, 2023, 6:05am UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/3 "2023-09-08T06:05:33Z")

</div>

**This is an exception from test client:**  
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'

**This is the code (c#):**

```auto
using System.Security.Authentication;
using System.Text;
using RabbitMQ.Client;

var factory = new ConnectionFactory { HostName = "my1.example.com", UserName="guest",Password= "guest", VirtualHost = "/",
    Port = 5672, Ssl = new SslOption { Enabled = true }
};
using var connection = factory.CreateConnection();

```

**This is docker compose of traefik:**

```auto
version: '3'

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.10.4
    container_name: traefik
    # restart: always
    # Enables the web UI and tells Traefik to listen to docker
    #network_mode: "host" #nefunguje
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
      - "443:443"
      - "5432:5432"
      - "5672:5672"
      - "1883:1883"
    volumes:
      # So that Traefik can listen to the Docker events
      - ./:/etc/traefik
      - ./data/traefik.yml:/traefik.yml:ro

```

**Traefik config:**

```auto
api:
   dashboard: true
   #insecure: true

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
          permanent: true
  websecure:
    address: ":443"
    http:
      tls:
        certResolver: letsencrypt
  postgres:
    address: ":5432"
  rabbitmq:
    address: ":5672"
  mqtt:
    address: ":1883"
# pilot:
# dashboard: true

#tracing: {}
log:
  level: DEBUG

providers:
  http:
    endpoint: "http://traefikkonfigurace/traefik.conf"

certificatesResolvers:
  letsencrypt:
     acme:
       email: ********
       storage: acme.json
       keyType: EC384
       httpChallenge:
         entryPoint: web

```

**RabbitMQ docker compose**

```auto
version: "3.2"
services:
  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: 'rabbitmq'
    #ports:
    # - 5672:5672
    # - 15672:15672
    volumes:
        - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
        - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
    networks:
        - traefik_default

networks:
  traefik_default:
    external: true

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 8, 2023, 8:57am UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/4 "2023-09-08T08:57:09Z")

</div>

Traefik is not in the same Docker network as RabbitMQ, so Traefik can not forward requests to RabbitMQ.

---

<div class="post-metadata">

**Author:** ![mscrocdile](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mscrocdile](https://community.traefik.io/u/mscrocdile)\
**Post date:** [September 8, 2023, 2:12pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/5 "2023-09-08T14:12:46Z")

</div>

How is that possible?  
If i run

```auto
docker inspect rabbitmq -f "{{json .NetworkSettings.Networks }}"

```

```auto
docker inspect traefik -f "{{json .NetworkSettings.Networks }}"

```

then both containers traefik and rabbitmq return result beginning with same network:

```auto
{"traefik_default":{"IPAMConfig":null,"Links":null,"Aliases":["rabbitmq", ...

```

```auto
{"traefik_default":{"IPAMConfig":null,"Links":null,"Aliases":["traefik","revers ...

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 8, 2023, 6:05pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/6 "2023-09-08T18:05:17Z")

</div>

I don’t understand your point. Why is the result cut short?

According to your configs, RabbitMQ is connected to `traefik_default`, Traefik is not.

---

<div class="post-metadata">

**Author:** ![mscrocdile](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mscrocdile](https://community.traefik.io/u/mscrocdile)\
**Post date:** [September 11, 2023, 1:52pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/7 "2023-09-11T13:52:16Z")

</div>

It is not true.  
Traefik is connected to traefik\_default.

```auto
docker exec -it traefik sh
/ # ping rabbitmq
PING rabbitmq (172.19.0.5): 56 data bytes
64 bytes from 172.19.0.5: seq=0 ttl=64 time=0.170 ms
64 bytes from 172.19.0.5: seq=1 ttl=64 time=0.135 ms
^C
--- rabbitmq ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.135/0.152/0.170 ms

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 11, 2023, 8:20pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/8 "2023-09-11T20:20:01Z")

</div>

According to compose files you posted, only RabbitMQ has

> [@mscrocdile](#):
>
> ```auto
> networks:
> - traefik_default
> 
> ```

What is `http://traefikkonfigurace/traefik.conf`?

---

<div class="post-metadata">

**Author:** ![mscrocdile](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mscrocdile](https://community.traefik.io/u/mscrocdile)\
**Post date:** [September 12, 2023, 2:29pm UTC](https://community.traefik.io/t/cannot-connect-to-rabbitmq-using-letsencrypt/19772/9 "2023-09-12T14:29:18Z")

</div>

traefik\_default was created when i first started docker compose from folder named traefik.  
I use it always this way and it just works and traefik use this network by default.

`http://traefikkonfigurace/traefik.conf `is just local web site providing dynamic configuration mentioned in my first comment here.  
`https://my.example.com ` works well so i suppose it is correct
