不知為何,前端ws訪問1883端口總是失敗
在阿里雲服務器配置了mosquitto消息服務器
添加更改配置文件 /etc/mosquitto/conf.d/myconfig.conf
1 # 配置mosquitto支持websocket,且監聽端口號為8083 2 port 1883 3 listener 8083 4 protocol websockets 5 6 # 關閉匿名訪問,客戶端必須使用用戶名 7 allow_anonymous false 8 9 #指定 用戶名-密碼 文件 10 password_file /etc/mosquitto/pwfile.txt
這樣,前端就可以用 client = mqtt.connect('ws://120.79.x.x:8083',options) 來訪問了