Laravel Echo Server and Socketio With ProxyPass dont work

  apache, laravel, laravel-echo, php, socket.io

i have an aplication with laravel 8 and php 7.4. I use laravel broadcasting to send notifications to cliens, with redis, laravel-echo-server and socketio. All is working perfect, but i need to make with a proxypass in my public server and i cant get it to work.
Without the proxypass all is working perfect, i have laravel echo server with ssl and the client connect with wss and work, but withno with proxypass.

My laravel echo server is running in 6001 port.
In Firefox its say cant conect to wss://XXXX.net/socket.io/?
EIO=3&transport=websocket.

Larave-echo-server.json:

{
    "authHost": "https://10.16.16.41:10081",
    "authEndpoint": "/broadcasting/auth",
    "clients": [],
    "database": "redis",
    "databaseConfig": {
            "redis": {
                    "host": "10.16.16.41",
                    "port": "10087"
            },
            "sqlite": {
                    "databasePath": "/database/laravel-echo-server.sqlite"
            }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "https",
    "socketio": {},
    "secureOptions": 67108864,
    "sslCertPath": "/etc/ssl/certs/AlphaSSL__.XXXXX.net.pem",
    "sslKeyPath": "/etc/ssl/private/AlphaSSL__.XXXXX.net.key",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
            "http": false,
            "redis": true
    },
    "apiOriginAllow": {
            "allowCors": true,
            "allowOrigin": "*",
            "allowMethods": "GET, POST",
            "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requeste>
    }

}

bootstrap.js in laravel

import Echo from 'laravel-echo'


 window.Echo = new Echo({
     broadcaster: 'socket.io',
     host: `${window.location.hostname}`,
     transports: ['websocket']
 });

apache site conf

<VirtualHost *:443>
ServerName devnew.app.XXXXX.net
DocumentRoot /var/www/app/public
<Directory /var/www/app>
                AllowOverride All
        </Directory>
        ErrorLog /error.log
        CustomLog /access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/AlphaSSL__.XXXXX.net.pem
SSLCertificateKeyFile /etc/ssl/private/AlphaSSL__.XXXXX.net.key



ProxyRequests off
ProxyVia on
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
RewriteCond %{QUERY_STRING} transport=websocket    [NC]
RewriteRule /(.*)           ws://localhost:6001/$1 [P,L]

ProxyPass        /socket.io http://127.0.0.1:6001/socket.io
ProxyPassReverse /socket.io http://127.0.0.1:6001/socket.io
</VirtualHost>

Source: Laravel

Leave a Reply