mqtt的nginx和websocket部署

本来mqtt用的好好的,公司信息安全把端口给封了,就给一个80,所以mqtt只能走这个端口,记录一下过程

1 生成密码文件 搞一个pwd.txt 写着username: pwd 然后 mosquitto_passwd -U passwordfile 就会生成一个pwd.txt

2 mosquitto的配置,注意要走websocket

bash 复制代码
persistence true
persistence_location /mosquitto/data

log_dest file /mosquitto/log/mosquitto.log


# 服务绑定的端口号 默认是1883 
# 服务绑定的IP地址 websockets 一定要在listener的下方,不然会错误
listener 18231 0.0.0.0
protocol websockets


allow_anonymous false
password_file /etc/mosquitto/pwd.txt

3 docker 启动命令,注意文件的映射:

bash 复制代码
docker run   -d --name mqtt  --net host --restart always -v /data/mqtt/log:/mosquitto/log -v /data/mqtt/data:/mosquitto/data  -v /data/mydocker/mqtt/mosquitto.conf:/mosquitto/config/mosquitto.conf  -v /data/mydocker/mqtt/pwd.txt:/etc/mosquitto/pwd.txt eclipse-mosquitto:latest

4 nginx的配置,位置在server里面,注意/mqtt是默认的,有的是/ws,我这个是/mqtt

bash 复制代码
  location /mqtt {
        proxy_pass "http://$myhost:18231";
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
  }
相关推荐
NineData30 分钟前
数据库管理工具NineData,一年进化成为数万+开发者的首选数据库工具?
运维·数据结构·数据库
梦想很大很大21 小时前
拒绝“盲猜式”调优:在 Go Gin 项目中落地 OpenTelemetry 链路追踪
运维·后端·go
Sinclair1 天前
内网服务器离线安装 Nginx+PHP+MySQL 的方法
运维
叶落阁主1 天前
Tailscale 完全指南:从入门到私有 DERP 部署
运维·安全·远程工作
十二7401 天前
前端缓存踩坑实录:从版本号管理到自动化构建
前端·javascript·nginx
可观测性用观测云2 天前
云原生网关 Ingress-Nginx 链路追踪实战:OpenTelemetry 采集与观测云集成方案
nginx·kubernetes
甲鱼9292 天前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
闲云一鹤4 天前
nginx 快速入门教程 - 写给前端的你
前端·nginx·前端工程化
碳基沙盒4 天前
OpenClaw 多 Agent 配置实战指南
运维
蝎子莱莱爱打怪7 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes