sukesh-ak / setup-mosquitto-with-docker

How to setup Mosquitto MQTT Broker using docker with Authentication and Websocket support.
https://www.sukesh.me
The Unlicense
166 stars 28 forks source link

How to add the domain and setup a secured MQTT broker for the VPS docker #5

Closed sayidhe closed 3 weeks ago

sayidhe commented 3 months ago

Hi,

I have successfully set up the Mosquitto Docker on my server, but I'm not sure how to add a domain for it and also enable Let's Encrypt.

sukesh-ak commented 3 months ago

Easiest way is to use CaddyServer as SSL proxy and expose websocket port. I have that setup already and will see if I get time to do the write-up.

sayidhe commented 3 months ago

I have tried to use Nginx, but still failed. I can connect through the IP address and port, but not through the domain.

The config file as below

server {
    server_name my_domain.com;

    location / {
        proxy_pass http://localhost:1883;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
sukesh-ak commented 3 months ago

This won't work since Websocket uses ws:// and Secure Websocket uses wss:// prefix. CaddyServer gives both Free SSL and reverse proxy together.

sukesh-ak commented 3 weeks ago

@sayidhe Check README.md 5.1 for instructions.