0

I have Laravel running in a Docker environment with the packages mysql,nginx and php-fpm. I use it as an API. I want to add the websocket, the server is started via php artisan websocket:serve using supervisor. I can't connect to the statistic laravel-websockets, I don't see any ping pong on console.

What am i doing wrong ?

broadcasting.php

   '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'),
            'scheme' => 'http',
            'host' => '127.0.0.1',
            'port' => 6001
        ],
    ],

ngnix.conf

map $http_upgrade $type {
default "web";
websocket "ws";
 }

server {
 listen 80 ;
 listen 444 ssl ;

client_max_body_size 520M;

access_log /var/log/nginx/application.access.log;
# mapping the entry point
root /application/Edidact_Backend/public;

# Deny all . files
location / {
    try_files $uri /index.php$is_args$args;
}
location @web  {
    try_files $uri $uri/ /index.php?$query_string;
  }
location @ws  {
  proxy_pass             http://php-fpm:6001;
  proxy_set_header Host  $host;
  proxy_read_timeout     60;
  proxy_connect_timeout  60;
  proxy_redirect         off;

# Allow the use of websockets
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}
# Handle Cache Files Automatically
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
    expires 30d;
    add_header Cache-Control "max-age=0, must-revalidate";
}
# Handleing Php Files
location ~ ^/index\.php(/|$) {
    fastcgi_pass php-fpm:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_index app.php;
    send_timeout 1800;
    fastcgi_read_timeout 1800;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    include fastcgi_params;
}

location ~ \.php$ {
    return 404;
}
# Statics
location /(bundles|media) {
    access_log off;
    expires 30d;
    try_files $uri @rewriteapp;

}

}

websockets.php

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
]

The containers

enter image description here

1 Answers1

0

As far as I can see your websocket server is not in the same container as your php server, so when you try to connect to localhost it fails.

If you want to connect to a different container you should use the name of that container instead of localhost, in your case:

'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'),
        'scheme' => 'http',
        'host' => 'php-fpm-service-V2', // Name of the php server
        'port' => 6001
    ],
],
Sjoertjuh
  • 1
  • 2