laravel-websockets
laravel-websockets copied to clipboard
Multiple websockets servers in one host
Hello,
I have a Laravel website up and running with websockets working fine with https, below Is the Echo.connector.options object that is currently working:
{
"auth": {
"headers": {}
},
"authEndpoint": "https://api.appname.com.br/broadcasting/auth",
"broadcaster": "pusher",
"csrfToken": null,
"host": "api.appname.com.br",
"key": "<DOMAIN>",
"namespace": "App.Events",
"wsHost": "api.appname.com.br",
"wssHost": "api.appname.com.br",
"httpHost": "api.appname.com.br",
"statsHost": "api.appname.com.br",
"forceTLS": true,
"wsPort": "6001",
"wssPort": "6001",
"cluster": "mt1",
"scheme": "https",
"encrypted": "true",
"disableStats": true
}
and the Laravel .env entries:
PUSHER_APP_ID=appname
PUSHER_APP_KEY=appname
PUSHER_APP_SECRET=appname-secret
PUSHER_APP_CLUSTER=mt1
PUSHER_APP_USE_TLS=true
PUSHER_APP_ENCRYPTED=true
PUSHER_APP_PORT=6001
PUSHER_APP_HOST=api.appname.com.br
PUSHER_APP_SCHEME=https
config\websockets.php
/*
* Set a custom dashboard configuration
*/
'dashboard' => [
'port' => env('PUSHER_APP_PORT', 6001),
],
/*
* This package comes with multi tenancy out of the box. Here you can
* configure the different apps that can use the webSockets server.
*
* Optionally you specify capacity so you can limit the maximum
* concurrent connections for a specific app.
*
* Optionally you can disable client events so clients cannot send
* messages to each other via the webSockets.
*/
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
],
config\broadcasting.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'),
'useTLS' => env('PUSHER_APP_USE_TLS'),
'encrypted' => env('PUSHER_APP_ENCRYPTED'),
'host' => env('PUSHER_APP_HOST'),
'port' => env('PUSHER_APP_PORT'),
'scheme' => env('PUSHER_APP_SCHEME'),
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
But that is production vhost, so we decided to create a staging area to test new functionalities. It will be different branches, but right now is the same branch. To be able to block the staging area via firewall to only be accessed by our company IP, we used custom ports and domains:
staging.appname.com.br:8443
staging-api.appname.com.br:8443
websocket port 6002
The Echo object:
{
"auth": {
"headers": {}
},
"authEndpoint": "https://staging-api.appname.com.br:8443/broadcasting/auth",
"broadcaster": "pusher",
"csrfToken": null,
"host": "staging-api.appname.com.br:8443",
"key": "appname-staging",
"namespace": "App.Events",
"wsHost": "staging-api.appname.com.br",
"wssHost": "staging-api.appname.com.br",
"httpHost": "staging-api.appname.com.br:8443",
"statsHost": "staging-api.appname.com.br:8443",
"forceTLS": true,
"wsPort": "6002",
"wssPort": "6002",
"cluster": "mt1",
"scheme": "https",
"encrypted": true,
"disableStats": true
}
Laravel .env
PUSHER_APP_ID=appname-staging
PUSHER_APP_KEY=appname-staging
PUSHER_APP_SECRET=appname-secret-staging
PUSHER_APP_CLUSTER=mt1
PUSHER_APP_USE_TLS=true
PUSHER_APP_ENCRYPTED=true
PUSHER_APP_PORT=6002
PUSHER_APP_HOST=staging-api.appname.com.br:8443
PUSHER_APP_SCHEME=https
And running
php artisan websockets:serve --port=6002
The server generates no input.
Browser console shows:
WebSocket connection to 'wss://staging-api.sympou.com.br:6002/app/sympou-staging?protocol=7&client=js&version=7.0.6&flash=false' failed:
Did I miss anything? Or is it not possible to run 2 instances in the same server or something? Or is there other way to have to separate apps runnig?