Hi,
I'm having trouble to connect to a broker via MQTT protocol to an adress which has a path in it due to the server being behind a nginx reverse proxy.
e.g. dom.ain.com/mqtt
When I provide a mqtt/tcp formated url (mqtt://...) I don't get a connection at all.
When I try the WS protocol, I get trough, but I'd like to be able to use both is possible.
I have seen that when I pick the websocket protocol I have the option to provide a path in the client options, which seems to work (as described in the ws.js).
The tcp.js doesn't offer anything there... does that mean paths aren't supported in the MQTT protocol?
My nginx settings are like this:
location ^~ /mqtt {
proxy_buffering off;
proxy_pass http://x.x.x.x:1883;
proxy_set_header X-Scheme $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Server;
}
This seems to work for the WS connection, but the MQTT protocol doesn't seem to like these settings... The connection attempt is immediately rejected in that case. Any ideas?
BR
I think your MQTT broker should expose a websocket server itself, you can't proxy from websocket to tcp in NGINX.
There is no concept of Path in TCP connectivity. You can only connect to an IP address and Port.
Check out this gist how to use a NGINX as a load balancer for TCP mode.
Thanks @akashgoswami!
Most helpful comment
There is no concept of Path in TCP connectivity. You can only connect to an IP address and Port.
Check out this gist how to use a NGINX as a load balancer for TCP mode.