Mosquitto with letsencrypt certaficat error :connection refused

i have a domain and i installed cert bot to generate certificates for my domain and i succeeded.
i have an ubuntu 20.04 with nginx and a docker-compose that contain a docker for node-red, grafana, influx and mosquitto every thing was working fin until i decided to secure my mosquitto broker with lets-encrypt certificate i got the message error :connection refused and i have seen that my mosquitto docker keeps restarting for the mosquitto conf file i have added these lines
indent preformatted text by 4 spaces

listener 8883
certfile /etc/letsencrypt/live/Mydomain.fr/cert.pem
cafile /etc/letsencrypt/live/Mydomaine.fr/chain.pem
keyfile /etc/letsencrypt/live/Mydomaine.fr/privkey.pem

in my dockercompose.yaml i have mapped the port of my mosquitto broker to 8883
what could be the problem

1 Like

Are your certificate files accessible from that broker container? If the file is located at host machine, you need to allow that container to access it.

2 Likes

i thought that was the problem so i copied the certificates to the folder of the mosquitto container and changed /etc/letsencrypt/live/Mydomain.fr/cert.pem with /home/docker/docker-compose/data/mosquitto/certs/ and it didn't work

1 Like

P.S. if you say the docker keep restarting, do you know what's the error from that container?
You can generally view logs of container with docker logs your_container_id or docker-compose logs your_container_id

3 Likes

1603201252: mosquitto version 1.6.12 starting
1603201252: Config loaded from /mosquitto/config/mosquitto.conf.
1603201252: Opening ipv4 listen socket on port 1883.
1603201252: Opening ipv6 listen socket on port 1883.
1603201252: Error: Unable to load CA certificates. Check cafile "/etc/letsencrypt/live/Mydomaine.com/chain.pem".
1603201252: OpenSSL Error[0]: error:02FFF002:system library:func(4095):No such file or directory
1603201252: OpenSSL Error[1]: error:20FFF080:BIO routines:CRYPTO_internal:no such file
1603201252: OpenSSL Error[2]: error:0BFFF002:x509 certificate routines:CRYPTO_internal:system lib

just a remark i have changed the port 8883 with 1883

1 Like

This means the certificate chain file was not found.
Can you share your docker's file commands (how you linked host files to docker container)?

3 Likes

this is my docker compose.yaml

MyMosquitto:
image: eclipse-mosquitto
ports:
- 60012:8883
restart: always
volumes:
- ./data/mosquitto/:/mosquitto/config/
networks:
network:
ipv4_address: 192.171.0.5

1 Like

I think this is the issue, you are only sharing ./data/mosquitto/. There's definitely a file reference to /etc/letsencrypt/

Do you mind add the below line into volumes and see what will happen?
- /etc/letsencrypt/live/Mydomaine.com/:/etc/letsencrypt/live/Mydomaine.com/
Replace mydomaine.com to your real path reference.

P.S. IMO it might be better to have your host machine handle reverse proxy + SSL termination if possible (for small personal projects)... it's just easier.

Thank you

3 Likes

even though i changed etc/letsencrypt/live/Mydomaine.com/ in mosquitto.conf with home/docker/docker-compose/dol/data/mosquitto/ and i have always the same problem

1603203106: Error: Unable to load CA certificates. Check cafile "/home/docker/docker-compose/dol/data/mosquitto/certs/chain.pem".
1603203106: OpenSSL Error[0]: error:02FFF002:system library:func(4095):No such file or directory
1603203106: OpenSSL Error[1]: error:20FFF080:BIO routines:CRYPTO_internal:no such file
1603203106: OpenSSL Error[2]: error:0BFFF002:x509 certificate routines:CRYPTO_internal:system lib

when i added the line to the volume the logs are
603203266: Config loaded from /mosquitto/config/mosquitto.conf.
1603203266: Opening ipv4 listen socket on port 1883.
1603203266: Opening ipv6 listen socket on port 1883.
1603203266: Error: Unable to load CA certificates. Check cafile "/etc/letsencrypt/live/Mydomin.com/chain.pem".
1603203266: OpenSSL Error[0]: error:02FFF002:system library:func(4095):No such file or directory
1603203266: OpenSSL Error[1]: error:20FFF080:BIO routines:CRYPTO_internal:no such file
1603203266: OpenSSL Error[2]: error:0BFFF002:x509 certificate routines:CRYPTO_internal:system lib

I was looking up error messages and discover this thread, can you double check what user this docker is running?

3 Likes

What happens if you change this:

to this:

certfile /etc/letsencrypt/live/Mydomain.fr/fullchain.pem
keyfile /etc/letsencrypt/live/Mydomaine.fr/privkey.pem

OR this:

certfile /etc/letsencrypt/live/Mydomain.fr/cert.pem
keyfile /etc/letsencrypt/live/Mydomaine.fr/privkey.pem

I wonder...

[&2* readers: Get involved; Be heard. It starts with: if you read something you like, then like it :heart:]

3 Likes

Ii think i have found a solution is by copying the certificat to my docker container now i have a nother problem: when i do mosquitto_pub i can see the data on mynode -red but if i do inject data with the node red i can't recieve it it's a weird problem

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.