T
T
thisall2021-01-27 18:59:57
Laravel
thisall, 2021-01-27 18:59:57

How to make Laravel WebSocket work?

I'm trying to run the dashboard and it gives me an error. I want to run on https

pusher.min.js:8 WebSocket connection to 'wss://chat.domain.ru:6001/app/1234?protocol=7&client=js&version=7.0.2&flash=false' failed: WebSocket opening handshake was canceled


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'),
                'host' => '127.0.0.1',
                'post' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]
            ],
        ],


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


.env

APP_URL=http://chat.domain.ru
PUSHER_APP_ID=1234
PUSHER_APP_KEY=1234
PUSHER_APP_SECRET=1234
PUSHER_APP_CLUSTER=eu
PUSHER_APP_HOST=127.0.0.1


nginx conf

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

server {

  server_name chat.domain.ru;

  root /var/www/nginx/chat/public;
  index index.php index.html;

    index index.php;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;

    location @web {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location @ws  {
        proxy_pass             https://127.0.0.1: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;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    listen 443 ssl;
}


Maybe someone faced such a problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thisall, 2021-01-27
@thisall

Solved the problem by setting ssl certificate in config/websockets.php ['ssl']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question