how to do reverse proxy on docker

强颜欢笑 提交于 2021-02-05 11:12:55

问题


I have a server and I am using Ubuntu 20.04, nginx , mosquitto and node-red and docker , let's call the website http://mywebsite.com. The problem that I am facing that I have created a client lets call it client1 in docker so the URL will be http://mywebsite.com/client1 and I want to establish an MQTT connection via mosquitto and I'm sending the data on topic test

The problem that on node red node of MQTT when I write the IP address of my mosquitto container it works

enter image description here

But if I change the IP address 192.144.0.5 with mywebsite.com/client1 I can't connect to mosquitto and I can't send or receive any form of data

enter image description here

any idea on how to solve this problem


回答1:


OK, you are going to have several problems here.

  1. You can not do path based proxying with MQTT. If you want to have multiple MQTT brokers (1 per client) bound to a single public facing domain/IP address then they are all going to have to run on separate ports (other than the default 1883).

    Nginx can do MQTT protocol proxying (e.g. like this), so you can use this to expose the different ports and forward them to the separate instances of mosquitto, but even if you had a different hostname (all pointing at the same IP address) nginx has no way to know which host name was used because there is no equivalent to the HOST HTTP header to direct it. If you were to use MQTT with TLS then you may be able to get it to work with SNI, but I've never seen anybody do that yet (possible docs for SNI based routing here) It works, explanation about how to do it here.

    If you use MQTT over Websockets then you should be able to use hostname based routing.

  2. Path based proxying for Node-RED currently doesn't work properly if you enable admin authentication, because the admin auth tokens are currently stored in browser local storage and only scoped to the hostname, not the hostname + path. This will mean that a client will only ever be able to log into one instance at a time.

    You can work round this by using host based proxying, e.g. http://client1.mywebsite.com

    A fix for this is on the backlog for Node-RED, probably (no promises) to be looked at after version 1.2.0 ships



来源:https://stackoverflow.com/questions/64338203/how-to-do-reverse-proxy-on-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!