0

我们已经为网站上的实时聊天应用程序配置了 laravel websockets,使用代码端完成了翻转,并且在 localhost 上工作正常,但无法在实时服务器上配置它。尝试使用 websockets 设置实时环境,在本地环境中正常工作。

虚拟主机文件

<VirtualHost *:80>
    ServerName ws.techandover.com
#    ProxyPass "/" "ws://127.0.0.1:6001/"

    RewriteEngine on
    ProxyRequests off
    ProxyPreserveHost On
    ProxyVia on

 # allow for upgrading to websockets
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)           ws://localhost:6001/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)           http://localhost:6001/$1 [P,L]


  ProxyPass "/" "http://localhost:6001/"
  ProxyPassReverse "/" "http://localhost:6001/"

  ProxyPass "/app" "ws://localhost:6001/app"
  ProxyPassReverse "/app" "ws://localhost:6001/app"


    ErrorLog ${APACHE_LOG_DIR}/websocket-error.log
    CustomLog ${APACHE_LOG_DIR}/websocket-access.log combined

    <FilesMatch \.php> # Apache 2.4.10+ can proxy to unix socket
          SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
    </FilesMatch>
    <Proxy *>
        Require all granted
        Allow from all
    </Proxy>
</VirtualHost>

广播.php

'connections' => [

        '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'),
                'encrypted' => true,
                'host' => 'ws.techandover.com',
                'port' => 6001,
                'scheme' => 'http'
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],

    ],

回声

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    authEndpoint : 'https://medservice.techandover.com/broadcasting/auth',
    encrypted: true,
    auth : {
      headers:{
      'Authorization': 'Bearer ' + localStorage.getItem('patient_access_token')
      }
    },
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: 'ws.techandover.com',
    wsPort: 6001,
    forceTLS: false,
    disableStats: false,
    
});

当我们尝试使用上述配置与 pusher/websocket 连接时,WebSocket 连接失败错误截图

4

0 回答 0