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;
  }
相关推荐
碳基沙盒3 小时前
OpenClaw 多 Agent 配置实战指南
运维
蝎子莱莱爱打怪3 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
何中应3 天前
Nginx转发请求错误
前端·后端·nginx
DianSan_ERP4 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅4 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒4 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
芝士雪豹只抽瑞克五4 天前
Nginx 高性能Web服务器笔记
服务器·nginx
zhangfeng11334 天前
趋动云 如何ssh登录 服务区 项目server
运维·人工智能·ssh
ZeroNews内网穿透4 天前
谷歌封杀OpenClaw背后:本地部署或是出路
运维·服务器·数据库·安全