带有SSL配置的Laravel Websockets不工作



Laravel Websockets不使用Https,在没有ssl配置的情况下工作得很好尝试了doculnetion链接中的所有内容https://beyondco.de/docs/laravel-websockets/basic-usage/ssl但是什么都没用

这里是我的websockets配置

brodcasting.php

'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
], 

bootstrap.js

window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
enabledTransports: ['ws','wss'],
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
axios.post('/api/broadcasting/auth', {
socket_id: socketId,
channel_name: channel.name
}).then(({data}) => {
callback(false, data);
}).catch(error => {
callback(true, error);
});
}
};
}
}); 

.env

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/letsencrypt/live/xxxxxxxx/fullchain.pem
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/letsencrypt/live/xxxxxxxxxx/privkey.pem

websockets.php

'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'capath' => env('LARAVEL_WEBSOCKETS_SSL_CA', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => env('LARAVEL_WEBSOCKETS_SSL_PASSPHRASE', ''),
'verify_peer' => env('APP_ENV') === 'production',
'allow_self_signed' => env('APP_ENV') !== 'production',
],

我已经为我找到了解决方案,issue是用LetsEncrypt ssl在中做了一些更改

在default.conf中添加到可用站点

# Added this for Web Sockets Proxy 
location /ws/ {
proxy_pass             http://127.0.0.1:6001;
proxy_set_header Host  $host;
proxy_read_timeout     60;
proxy_connect_timeout  60;
proxy_redirect         off;
# Allow the use of websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

在supervior中改变了

user=root
commad=sudo /usr/bin/php /var/www/html/TestFolder/artisan websockets:serve
[program:websockets]
command=sudo /usr/bin/php /var/www/html/TestFolder/artisan websockets:serve
numprocs=1
autostart=true
autorestart=true
user=root
redirect_stderr=true

之后

sudo supervisorctl update websockets
sudo supervisorctl restart all

它神奇地发挥了作用,希望这能有所帮助!

相关内容

  • 没有找到相关文章

最新更新