MQTT 限制匿名用户访问,开启用户密码认证
刚搭建的emq服务默认是开启匿名用户访问的,这样的环境非常不安全,只要知道ip地址就可以连接,所以强烈建议开启用户认证,设置密码!
1、首先找到安装mqtt 的路径
我这里的路径是:
cd /www/server/emqx/bin
2、修改配置文件
vim /etc/emqx/emqx.conf
修改true为false
allow_anonymous = false

2、重启服务
emqx stop
emqx start
或这个这种方法 重启
ps -ef |grep emq
kill -9 27964
systemctl start emqx
3、安装插件
cd /usr/lib/emqx/bin
sh emqx_ctl plugins load emqx_auth_username
4.设置账号密码
emqx_ctl users add admin public

Nginx 配置
#wss协议转发 小程序里面要访问的链接 # 访问:wss://xxxx.com/wss location /mqtt { proxy_pass http://IP:8089;#代理到上面的地址去, proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; }