Ssl 在同一个代理中使用MQTT和WSS的MOSQUITO

Ssl 在同一个代理中使用MQTT和WSS的MOSQUITO,ssl,mqtt,mosquitto,Ssl,Mqtt,Mosquitto,我正在尝试使用安全连接设置Mosquitto代理 我能够使用MQTTS进行配置并使其正常工作,我能够使用ESP32和MQTTBox进行测试 现在我尝试使用websocket连接web应用程序,但我相信我在某些MOSQUITO配置中失败了 对于MQTT,我使用了“CA签名服务器证书”和端口8083,MQTTBox和ESP32的一切都很好 我花了整个周末研究和尝试不同的配置,但我无法使连接在两个方面都工作。有人能帮我吗?谢谢 # First of all, use this options on m

我正在尝试使用安全连接设置Mosquitto代理

我能够使用MQTTS进行配置并使其正常工作,我能够使用ESP32和MQTTBox进行测试

现在我尝试使用websocket连接web应用程序,但我相信我在某些MOSQUITO配置中失败了

对于MQTT,我使用了“CA签名服务器证书”和端口8083,MQTTBox和ESP32的一切都很好

我花了整个周末研究和尝试不同的配置,但我无法使连接在两个方面都工作。有人能帮我吗?谢谢

# First of all, use this options on mosquitto.conf
per_listener_settings true
allow_anonymous false
password_file /usr/local/etc/mosquitto/pwfile.conf

# Rules for access topics
acl_file /usr/local/etc/mosquitto/aclfile.conf

# Now, use this options on mosquitto.conf
listener 8883
cafile /usr/local/etc/mosquitto/certs/ca.crt
certfile /usr/local/etc/mosquitto/certs/server.crt
keyfile /usr/local/etc/mosquitto/certs/server.key

listener 8083
websockets
cafile /usr/local/etc/mosquitto/certs/ca.crt
certfile /usr/local/etc/mosquitto/certs/server.crt
keyfile /usr/local/etc/mosquitto/certs/server.key
编辑,这是Mosquitto日志:

1621899173: mosquitto version 2.0.10 starting
1621899173: Config loaded from /usr/local/etc/mosquitto/mosquitto.conf.
1621899173: Opening ipv6 listen socket on port 8883.
1621899173: Opening ipv4 listen socket on port 8883.
1621899173: Opening websockets listen socket on port 8083.
1621899173: mosquitto version 2.0.10 running
1621899174: Sending CONNACK to ::ffff:192.168.15.2 (0, 5)
1621899174: Client <unknown> closed its connection.
1621899176: Sending CONNACK to ::ffff:192.168.15.2 (0, 5)
1621899176: Client <unknown> closed its connection.
1621899177: Sending CONNACK to ::ffff:192.168.15.2 (0, 5)
1621899177: Client <unknown> closed its connection.
openssl genrsa -des3 -out ca.key 2048
openssl req -new -x509 -days 1826 -key ca.key -out ca.crt
openssl genrsa -out server.key 2048
openssl req -new -out server.csr -key server.key
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360
openssl x509 -in server.crt -sha1 -noout -fingerprint

从手册页

协议

为当前侦听器设置要接受的协议。可以是mqtt、默认值或WebSocket(如果可用)

默认情况下,WebSocket支持在编译时当前处于禁用状态。基于证书的TLS可与WebSocket一起使用,但以下情况除外: 只有cafile、certfile、keyfile、密码和密码\u tls1.3 支持选项

未在重新加载信号时重新加载

您的Websockets侦听器应该如下所示

listener 8083
protocol websockets
cafile /usr/local/etc/mosquitto/certs/ca.crt
certfile /usr/local/etc/mosquitto/certs/server.crt
keyfile /usr/local/etc/mosquitto/certs/server.key

对不起,我在Stackoverflow上打错了。正如您所说,我的配置文件已经包含“协议websockets”。如果没有至少一些关于实际错误的指示,将无法回答。“连接错误”本身并没有告诉我们任何有用的东西。使用MOSQUITO和您用于测试的客户端的相关日志输出更新问题(代理证书必须由公共CA签署,WSS才能使用web浏览器)。感谢您的关注@hardillb。我用log.Run
mosquitto-v-c/path/to/config/file.conf
更新了这个问题,以查看是否有任何明显的错误。可悲的是,你并不孤单。我自己寻找wss://函数的过程也遇到了同样的挫折,而mosquitto文档也非常糟糕。。