Сбой соединения WebSocket с 'wss: //test.example.com: 8090 /': истекло время ожидания открытия WebSocket - PullRequest
0 голосов
/ 17 января 2019

Я использую https и подключение к websocket для проекта Laravel. Я настроил виртуальный хост, как показано ниже:

<VirtualHost *:80>
ServerName test.example.com
ServerAdmin test.example.com
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>

ServerAdmin test.example.com
ServerName test.example.com

SSLEngine on
SSLCertificateFile "cert.pem"
SSLCertificateKeyFile "privkey.pem"
SSLCertificateChainFile "chain.pem"

SSLProxyEngine On
ProxyPreserveHost On
ProxyRequests Off

ProxyPass /wss wss://test.example.com:8090/
ProxyPassReverse /wss wss://test.example.com:8090/

DocumentRoot "/var/www/html/laravel/public"
<Directory "/var/www/html/laravel/public">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride all
    Require all granted
</Directory>
</VirtualHost>

Но в браузере отображается ошибка:

   WebSocket connection to 'wss://test.example.com:8090/' failed: WebSocket opening handshake timed out

Не могли бы вы помочь нам, что может быть проблемой?

Заранее спасибо

1 Ответ

0 голосов
/ 20 марта 2019

, если вы используете библиотеку laravel cboden / ratchet для сокета затем перейдите в приложение / Консоль / Команды / WebSocketServer.php Замените функцию handle этими строками кода и используйте путь к файлу сертификации 'local_cert' и 'local_pk'

public function handle()
{

    $loop   = Factory::create();
    $webSock = new SecureServer(
        new Server('0.0.0.0:8090', $loop),
        $loop,
        array(
            'local_cert'        => '/opt/ssl/chamberstock_com.crt', // path to your cert
            'local_pk'          => '/opt/ssl/server.key', // path to your server private key
            'allow_self_signed' => TRUE, // Allow self signed certs (should be false in production)
            'verify_peer' => FALSE
        )
    );
    // Ratchet magic
    $webServer = new IoServer(
        new HttpServer(
            new WsServer(
                new WebSocketController()
            )
        ),
        $webSock
    );
    $loop->run();

}
...