简体   繁体   中英

Laravel websockets and amazon web service (AWS)

Im trying to deploy my laravel app with laravel websockets using an EC2 instance ubuntu server.

But then when i try to serve the artisan using php artisan websockets:serve , and im expecting to see some console logs upon connection but i only receive an information of

Starting the WebSocket server on port 6001...

I tried to debug the data by visiting example.com/laravel-websockets . And it only returns

WebSocket is closed before the connection is established

Im just confused if laravel-websocket can be deployed to amazon web service ec2 instance or is there any configuration to aws need to do to be able to run this laravel-websockets?

Client side

import Echo from "laravel-echo"

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: VUE_APP_PUSHER_APP_KEY,
    wsHost: VUE_APP_PUSHER_HOST,
    wsPort: 6001,
    wssPort: 6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],
    encrypted: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'),
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]
            ],
        ],

Websocket response

Websocket 响应

this is my bootstrap.js configuration: use window.location.hostname, for ws and wss port.

and plain key.

Also, check whether ec2 instance block 6001 port or not.

import Echo from "laravel-echo"

window.Pusher = require('pusher-js');


window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '1234567890',
    wsHost: window.location.hostname,
    wsPort: 6001,
    wssHost: window.location.hostname,
    wssPort: 6001,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],
});

Try to see the port is listening or not:

netstat -tpunl | grep 6001

If it is there. I think EC2 instance server disable external access port 6001.

You need to open port 6001 in the ec2 Security Group .

Also need to open the same port on the EC2 instance's firewall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM