Websocket无法与SSL一起使用 [英] Websocket is not working with SSL

查看:385
本文介绍了Websocket无法与SSL一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.hi-todd.com/websocket/

我已经创建了一个使用MQTT协议的演示,并且可以通过HTTP连接正常运行.但是,当我尝试将HTTP更改为https时,它会收到连接错误.

我已在mosquitto.conf文件中添加了证书路径.让我与您分享Mosquitto的配置路径.

# WebSockets over TLS/SSL
listener 8083
protocol websockets
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/ca_certificates/hi-todd_com.crt
keyfile /etc/mosquitto/ca_certificates/hi-todd_com.p7b

我使用了下面的库代码.

https://www.cloudmqtt.com/docs-websocket.html

解决方案

现在我们已经解决了所有其他问题.

您使用的证书的CN值为hi-todd.com,备用CN值为

DNS:hi-todd.com, DNS:www.hi-todd.com

这意味着它仅对那些主机有效.在您的config.js中,您通过主机的IP地址来引用该主机,因此它与证书不匹配.这将导致浏览器以不安全的方式拒绝连接.

要解决此问题,请使您的config.js使用主机名而不是IP地址.

https://www.hi-todd.com/websocket/

I have created one demo with MQTT protocol and it is working fine with HTTP connection. But when I tried to change HTTP to https then it is getting a connection error.

I have added certificate path in mosquitto.conf file. Let me share with you Mosquitto config path.

# WebSockets over TLS/SSL
listener 8083
protocol websockets
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/ca_certificates/hi-todd_com.crt
keyfile /etc/mosquitto/ca_certificates/hi-todd_com.p7b

I have used below library code.

https://www.cloudmqtt.com/docs-websocket.html

解决方案

Now we've fixed all the other issues.

The certificate you are using has a CN of hi-todd.com and has alternate CNs of

DNS:hi-todd.com, DNS:www.hi-todd.com

This means it's only valid for those hosts. In your config.js you are referencing the host by it's IP address so it will not match the certificate. This will cause the browser to reject the connection as insecure.

To fix this make your config.js use the hostname not the ip address.

这篇关于Websocket无法与SSL一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆