MQTT-Apache Reverse-Proxy


Why my MQTT server was set up to fail from the start (mosquitto) after the reverse-proxy is configured in apache ? in addition, to re-activate it again, I have been obliged to put the mosquitto -v command in each process failure,.

it’s should reverse mosquitto too?


Simple answer: no! :wink:
Long answer: you should read more on protocols and services, which only accidentially use TCP/IP for transportation.

In short:

  • reverse-proxy for Apache WebServer is for Web-Traffic (usually port 80 http or port 443 for secure https)
  • MQTT for the MQTT-protocol (usually 1883 or port 8883 for secure TLS)

both use TCP/IP for transportation, but that’s all what they have in common. so no, reverse-proxy has nothing to do with MQTT.

(note: MQTT can use non-TCP networks like Zigbee for transportation also)

Clear response, thank you Thomas. But what 's about the stopping of mosquitto?. it happens only when I set the reverse configuration.

What’s your Apache configuration? and where is your broker running? on the same machine?

In 000-default.conf

ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Broker: mosquitto ; Yes is Running on the same machine at localhost:1883;

If that’s the only lines in your config, you’re rerouting all ports, including your MQTT ports.

Try this one:

<VirtualHost *:80> 
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

Openhab with reverse proxy perfectly works, but mosquitto crashes sometimes. here is below the log from openhab-cli console :face_with_raised_eyebrow:

[ERROR] [] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: Unable to connect to server
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start( []
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ []
at [?:?]
Caused by: Connection refused (Connection refused)
at Method) ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start( ~[?:?]
… 2 more

I’m not sure but it’s appeared to me that the problem is caused by the APIPA Address, because the RPI was randomly changing his address. So to fix it I reserved a static ip then mosquitto no longer stopped.