Mqtt.js: Connection via reverse proxy (nginx) over MQTT protocol (not ws) with path

Created on 7 Feb 2017  路  3Comments  路  Source: mqttjs/MQTT.js

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

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.

All 3 comments

I think your MQTT broker should expose a websocket server itself, you can't proxy from websocket to tcp in NGINX.

See also https://www.nginx.com/blog/websocket-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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jingzhaoou picture jingzhaoou  路  4Comments

jeffdare picture jeffdare  路  9Comments

hijklmno picture hijklmno  路  7Comments

renerlemes picture renerlemes  路  5Comments

amerllica picture amerllica  路  3Comments