问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/45560795/websocket-is-not-working-with-ssl