WebSocket与“ wss://test.example.com:8090 /”的连接失败:WebSocket打开握手超时

时间:2019-01-17 08:15:05

标签: ssl websocket apache2 vhosts ratchet

我在Laravel项目中使用https和websocket连接。我已经设置了虚拟主机,如下所示:

<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 :(得分:0)

如果您将laravel库cboden / ratchet用于套接字 然后转到app / Console / Commands / WebSocketServer.php 用这些代码行替换句柄功能,并使用您的认证文件路径“ 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();

}