Setup and Secure MQTT websocket broker with Nginx

Architecture of MQTT

Overview

  1. Download Mosquitto MQTT.
  2. Build and Install Mosquitto MQTT with websocket enabled.
  3. Configure Mosquitto MQTT.
  4. Install Nginx and configure.
  5. Install Certbot and create certificate.
  6. Test Everything.

Links

  1. Mosquitto MQTT (Version: 2.0.10):
  2. Online Test Tool: http://tools.emqx.io/ (Do not use your original credentials it may get compromised.)

Steps

  1. First update the os.
sudo apt update && sudo apt upgrade -y
sudo apt install -y libwebsockets-dev build-essential libcjson1 libcjson-dev
wget https://mosquitto.org/files/source/mosquitto-2.0.10.tar.gz
tar -xvf mosquitto-2.0.10.tar.gz
cd mosquitto-2.0.10/
make WITH_WEBSOCKETS=yes
sudo make install
mosquitto --version
sudo mkdir /var/lib/mosquitto /etc/mosquitto/conf.d /var/log/mosquitto/
sudo touch /var/run/mosquitto.pid
sudo vi /etc/mosquitto/mosquitto.conf
sudo mosquitto_passwd -c /etc/mosquitto/passwd admin_user
sudo systemctl daemon-reload
sudo systemctl start mosquitto.service
sudo systemctl status mosquitto.service
sudo apt -y install nginx nginx-common
sudo vi /etc/nginx/conf.d/mqtt.conf
sudo ngixn -t
sudo systemctl restart nginx.service
sudo systemctl status nginx.service
sudo apt install -y certbot python3-certbot-nginxsudo certbot --nginx -d mqtt.sujitpatel.in#Follow certbot instructions to continue.sudo systemctl restart nginx.service

--

--

--

DevOps Engineer, Linux lover, Technology and Automation enthusiast. A strong believer in continuous learning.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Towards Analytics with Redis

Shows Redis Logo and SQL with a question mark? Asking the question if the Redis Data Structure Store can be used for analytics using SQL-Like Capabilities

How to fix TD Ameritrade App not working issue?

IIS & Always Encrypted Process

MacOS Security with Osquery and AWS Kinesis Firehose

Magento Lambda EFS/NFS integration

CodeScanner — Easy Way to Scan Code

Freeos: First Audit Milestone

How to Quickly Create and Unpack Lists with Pandas

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sujit Patel

Sujit Patel

DevOps Engineer, Linux lover, Technology and Automation enthusiast. A strong believer in continuous learning.

More from Medium

Setup MongoDB using docker-compose

Pass Environment variables to a NodeJS Project & deploy docker image to Kubernetes

Docker with NodeJS package.json

Simple Dockerfile to build nodejs application

Initialize MongoDB running on a Docker container