Boubou
2 weeks ago

Unable to setup Websockets on WSS on Apache 2.4 (Centos)

Posted 2 weeks ago by Boubou

Hello all,

I have been for 3 days on this and it is time for me to call it off, I cannot work it out and my server support refuses to help me further as they are not specialized in websockets. Using WS it works, but on WSS(https) it won't.

I am running Apache/2.4.41 (cPanel)

I have installed 3 php modules from the cpanel: -mod_proxy -mod_proxy_wstunnel -mod_proxy_http

My https.conf file has an external setting file in which I can drop some code(to stop me from editing the main.conf file).

I added this:

  SSLProxyEngine on
  SSLProxyVerify none 
  SSLProxyCheckPeerCN off
  SSLProxyCheckPeerName off
  SSLProxyCheckPeerExpire off

  RewriteEngine on
  ProxyRequests off
  ProxyPreserveHost on
  RewriteCond ${HTTP:Upgrade} websocket [NC]
  RewriteCond ${HTTP:Connection} upgrade [NC]
  RewriteRule .* "ws://mywebsite.com:6001/" [P,L]

ProxyPass /app ws://mywebsite.com:6001
ProxyPassReverse /app wss://mywebsite.com:6001

Reloaded httpd and tried to connect via the Laravel websocket panel. I have also followed the setup here: https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#configuration

As:

    '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' => false,
    ],

.env file in Laravel:

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/home/myaccount/public_html/ssl/ke_com_a25e6_65c3b_1577536339_5996f634be6fba7d72a3bcf7b.crt
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/home/myaccount/public_html/ssl/a25e6_65c3b_cc885c0c620bd3119e79f1fd.key

When clicking on the connect button of the laravel websocket dashboard, I get this error:

pusher.min.js:8 WebSocket connection to 'wss://mywebsite.com:6001/app/mnbmndbf090980df9g8dfgs0d980098fskjh?protocol=7&client=js&version=4.3.1&flash=false' failed: WebSocket opening handshake was canceled

I have nothing else in my logs.

Could someone please tell me if my httpd setup is correct?

Thank you.

Please sign in or create an account to participate in this conversation.