【问题标题】:Websocket ERR_SSL_PROTOCOL_ERROR over https通过 https 的 Websocket ERR_SSL_PROTOCOL_ERROR
【发布时间】:2020-07-20 13:44:37
【问题描述】:

我在服务器端使用 PHP 和 APACHE 网络服务器

如果我通过 HTTPS 使用安全 Web 套接字协议:

在客户端,我使用 Javascript 连接 websocket。以下是代码 `

var wsUri = wss://mywebsite.com:8012/test/web-socket    
    websocket = new WebSocket(wsUri); 

    websocket.onopen = function(ev) { // connection is open 
        $('#message_box').append("<div class=\"system_msg\">Connected!</div>"); //notify user
}`

我在建立连接时收到错误 net::ERR_SSL_PROTOCOL_ERROR

同样适用于 http

【问题讨论】:

  • 两者是否使用相同的证书进行保护?
  • 这能回答你的问题吗? How to deal with net::ERR_SSL_PROTOCOL_ERROR?
  • 否,因为该链接解释为仅在 https 上使用 js。我已经在 https 上使用 js。
  • 错误是一样的。同样的原因也适用于 websocket 连接
  • 错误是一样的,但是提到那个胎面的原因不适用于我的错误。最后,所有链接都仅通过 https 提供。

标签: php apache ssl websocket


【解决方案1】:

我已通过将证书和密钥组合文件提供给 stream_context_set_option 函数来解决此问题。这解决了 ssl_protocol_error。

$context = stream_context_create();         
stream_context_set_option($context, 'ssl', 'local_cert', '/tmp/combined_cert.pem');         
stream_context_set_option($context, 'ssl', 'passphrase', '');           
stream_context_set_option($context, 'ssl', 'allow_self_signed', true);          
stream_context_set_option($context, 'ssl', 'verify_peer', false);

【讨论】:

    猜你喜欢
    • 2020-04-19
    • 2016-04-20
    • 2020-11-22
    • 2017-01-22
    • 2016-11-19
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多