I tried to set up a new server with mosquitto. When I set up mosquitto on Ubuntu 18.04, both FireFox and Chrome can connect to it via websocket. When I set up the mosquitto on Ubuntu 20.04, only Chrome can connect to it via websocket. FireFox developer tools gives the error

The connection to wss://domain.example.com:10002/mqtt was interrupted while the page was loading.
Object { invocationContext: undefined, errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined." }

QUESTION: How do I either get mosquitto on Ubuntu 20.04 to behave the same way as Ubuntu 18.04, or get FireFox to connect to mosquitto on Ubuntu 20.04?

Steps to Reproduce Error

Here is the script that I use to install mosquitto on a clean installation of Ubuntu 18.04 or Ubuntu 20.04. I make sure to keep the same server and IP address, so the VPS instance DOES NOT change between each experiment:


# The following sensitive information has been substituted: somewebsitethatIown.com, example.com, username, password, ports 10001, 10002, 10009

apt-get update -y;

mkdir -p /etc/ssl/star.example.com/
cd /etc/ssl/star.example.com/
wget https://somewebsitethatIown.com/ssls.tar
tar xvf ssls.tar

cd ~/


apt-get install -y build-essential python quilt python-setuptools python3 libssl-dev cmake libc-ares-dev uuid-dev daemon libwebsockets-dev;

# user required for mqtt process
adduser --system --shell /bin/bash --group --disabled-password --home /home/mosquitto mosquitto;

mkdir -p ~/mqtt
cd ~/mqtt
wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz
tar zxvf mosquitto-1.4.10.tar.gz
cd mosquitto-1.4.10/
sed -i "s|WITH_WEBSOCKETS:=no|WITH_WEBSOCKETS:=yes|g" config.mk
make install
cp mosquitto.conf /etc/mosquitto

touch /etc/mosquitto/passwd
mosquitto_passwd -b /etc/mosquitto/passwd username password

mv /etc/mosquitto/mosquitto.conf /etc/mosquitto/mosquitto.conf.back

cat <<EOT >> /etc/mosquitto/mosquitto.conf
port 10009 localhost
listener 10001
certfile /etc/ssl/example.com/star.example.com.full.crt
cafile /etc/ssl/example.com/star.example.com.ca-bundle
keyfile /etc/ssl/example.com/STAR_example_com_key.txt
listener 10002
protocol websockets
certfile /etc/ssl/example.com/star.example.com.full.crt
cafile /etc/ssl/example.com/star.example.com.ca-bundle
keyfile /etc/ssl/example.com/STAR_example_com_key.txt
allow_anonymous false
password_file /etc/mosquitto/passwd

cat <<EOT >> /etc/systemd/system/mosquitto.service
ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

systemctl enable mosquitto.service;
systemctl start mosquitto.service;

Once this is up and running, I go to a different computer/server and create a simple react project as follows:

npx create-react-app mosq;
cd mosq;
npm install --save paho-mqtt;
rm src/App.js;
cat <<EOT >> src/App.js
import React from "react";
import { render } from "react-dom";
import Paho from "paho-mqtt";

const host = "domain.example.com;
const user = "username";
const pass = "password";

const topicWeb = "topic-web";
const port = 10002;

export default class App extends React.Component {

  componentDidMount() {

      try {
          const clientId = "id"+Math.random();
          const client = new Paho.Client(host, port, clientId);
          client.onConnectionLost = (response) => {
                  "MQTT Lost Connection: " +
            (response.errorCode !== 0
                ? response.errorMessage + " code: " + response.errorCode
                : "Unknown MQTT Error")
                console.log("MQTT Connected....");
            onFailure:e=>console.log("MQTT Error:", e),
      } catch (e) {

  render() {
    return <h1>hello world</h1>;

npm start;

Then I use FireFox or Chrome to visit http://localhost:3000 (or replace localhost with ip address of server hosting page). Chrome's developer tools will show MQTT Connected... regardless of whether I ran my mosquitto bash script on Ubuntu 18.04 or 20.04. FireFox will show MQTT Connected... if I ran my mosquitto bash script on Ubuntu 18.04, but show the error message The connection to wss://domain.example.com:10002/mqtt was interrupted while the page was loading. if I ran the mosquitto bash script on Ubuntu 20.04.

  • Are you running the same version of mosquitto on both machines?
    – hardillb
    Feb 17, 2021 at 18:53
  • i think so, I'm just doing a wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz shown in my bash script above. So I guess Ubuntu 20.04 compiles things differently?
    – John
    Feb 17, 2021 at 18:55
  • No, but you are likely linking against different versions of openssl
    – hardillb
    Feb 17, 2021 at 19:27


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.