【发布时间】:2021-09-01 19:15:51
【问题描述】:
我正在使用包beyondcode/laravel-websockets。
我的问题是当我设置'verify_peer' => true 时,websocket 不起作用,但是当值为false 时它正在工作。这里有没有人设法使它工作?
对于生产网站,我想将verify_peer 设置为true 以防止中间人攻击。
我有一个网站,比如说aceraven777.com,它已经安装了SSL(在cPanel 中它启用了autoSSL)。
在 websockets 配置中,我为证书和私钥输入了相同的路径(cPanel 生成的路径)。
chrome抛出错误:
WebSocket connection to 'wss://aceraven777.com:6001/app/asdfswerqwsafasfd?protocol=7&client=js&version=4.3.1&flash=false' failed:
createWebSocket @ pusher.min.js:8
这是firefox中的错误:
Firefox can’t establish a connection to the server at wss://aceraven777.com:6001/app/asdfswerqwsafasfd?protocol=7&client=js&version=4.3.1&flash=false. pusher.min.js:8:6335
以下是我使用的设置:
配置/websockets.php
'ssl' => [
/*
* Path to local certificate file on filesystem. It must be a PEM encoded file which
* contains your certificate and private key. It can optionally contain the
* certificate chain of issuers. The private key also may be contained
* in a separate file specified by local_pk.
*/
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
/*
* Passphrase for your local_cert file.
*/
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', null),
'verify_peer' => true,
],
config/broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'host' => env('PUSHER_APP_HOST'),
'port' => env('PUSHER_APP_PORT'),
'useTLS' => true,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 1,
CURLOPT_SSL_VERIFYPEER => 1,
],
],
// Configuration for laravel mix JS
'mix' => [
'host' => env('MIX_PUSHER_APP_HOST'),
'key' => env('MIX_PUSHER_APP_KEY'),
'cluster' => env('MIX_PUSHER_APP_CLUSTER'),
'port' => env('MIX_PUSHER_APP_PORT'),
],
],
【问题讨论】:
-
@Haridarshan,我的显示另一个错误:
WebSocket connection to 'wss://localhost:6001/app/asdfswerqwsafasfd?protocol=7&client=js&version=4.3.1&flash=false' failed。 -
能否分享完整的错误响应。
-
另外,您在 Chrome 或 Firefox 中也遇到此错误?
-
@Haridarshan 我编辑了我的问题,这些是 Chrome 和 firefox 中的完整错误响应。