Mosquitto 添加wss协议(HTTPS使用阿里云证书)

Mosquitto 添加wss协议(HTTPS使用阿里云证书)

1、准备证书

  

  

 **注意:根证书扩展名改为crt,

 

2、编辑mosquitto.conf配置文件

listener 88888
protocol websockets
cafile C:\mosquitto\crt\root.crt     //根证书
certfile C:\mosquitto\crt\public.crt //公共证书
keyfile C:\mosquitto\crt\cloud.key   //密钥文件

开放相应端口,重启服务

3、修改web客户端代码

var client = mqtt.connect("wss://www.xxxxxxx.com:88888", options)

将协议改为wss,ip地址要改为证书对应的域名,这样就大功告成了

posted @ 2022-03-16 20:06  中国结  阅读(1411)  评论(0编辑  收藏  举报