MQTT-Apache Reverse-Proxy

Hello,

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?

Thanks.

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/
</VirtualHost> 

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

[ERROR] [openhab.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: Unable to connect to server
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79) [221:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [221:org.openhab.io.transport.mqtt:1.11.0]
at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:?]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:?]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:?]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]
at java.net.Socket.connect(Socket.java:589) ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70) ~[?:?]
… 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.