【问题标题】:Unable to connect to Laravel Websockets with Forge, nginx & AWS无法使用 Forge、nginx 和 AWS 连接到 Laravel Websocket
【发布时间】:2019-11-16 12:45:01
【问题描述】:

几个月来一直坚持这一点。向后遵循所有教程。它在宅基地本地运行良好,但我被困在生产中,是时候寻求帮助了。

端口 6001 和 6002 在 Forge 和 AWS 安全组上开放。

在服务器上运行php artisan websockets:serve之后

在开发工具控制台中,我不再看到任何错误,但如果我输入

window.Echo.connector.pusher.connection.timeline.events

我明白了

0: {instances: 1, timestamp: 1573858516537}
1: {state: "connecting", params: undefined, timestamp: 1573858516540} 
2: {cached: true, transport: "ws", latency: 37966, timestamp: 1573858516558}
3: {cid: 1, transport: "wss", timestamp: 1573858516565}
4: {cid: 1, state: "initialized", params: undefined, timestamp: 1573858516565}
5: {cid: 1, state: "connecting", params: undefined, timestamp: 1573858516580}
6: {cid: 1, state: "open", params: undefined, timestamp: 1573858547531}
7: {state: "unavailable", params: undefined, timestamp: 1573858547707}
8: {state: "disconnected", params: undefined, timestamp: 1573858548832}
9: {cid: 1, state: "closed", params: {…}, timestamp: 1573858548887}

应该是(取自一个工作示例)

0: {instances: 1, timestamp: 1573859945413}
1: {state: "connecting", params: undefined, timestamp: 1573859945413}
2: {cid: 1, transport: "wss", timestamp: 1573859945419}
3: {cid: 1, state: "initialized", params: undefined, timestamp: 1573859945419}
4: {cid: 1, state: "connecting", params: undefined, timestamp: 1573859945422}
5: {cid: 1, state: "open", params: undefined, timestamp: 1573859945661}
6: {state: "connected", params: {…}, timestamp: 1573859945664}

真的希望有人能帮忙,这是我的配置

广播.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'),
         'encrypted'  => true,
         'host'       => '127.0.0.1',
         'port'       => 6001,
         'scheme'     => 'http'
     ],
 ],

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,
    ]
],

'local_cert' => null,
'local_pk' => null,
'passphrase' => null,

bootstrap.js

import Echo from 'laravel-echo';

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

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'my-key',
    wsHost: window.location.hostname,
    wsPort: 6002,
    wssPort: 6002,
    disableStats: false,
    encrypted: true,
    enabledTransports: ['ws', 'wss'],
});

nginx

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/mysite.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mysite.com;
    root /home/forge/mysite.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/mysite.com/int/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.com/int/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers abcd
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

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

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/mysite.com/server/*;

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

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

    access_log off;
    error_log  /var/log/nginx/mysite.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

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

server {
    listen 6002 ssl;
    listen [::]:6002 ssl;
    server_name mysite.com;
    root /home/forge/mysite.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/mysite.com/int/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.com/int/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers abcd
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

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

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/mysite.com/server/*;

    location / {
        proxy_pass             http://127.0.0.1:6001;
        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; }

    access_log off;
    error_log  /var/log/nginx/mysite.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

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

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/mysite.com/after/*;

【问题讨论】:

    标签: laravel amazon-web-services nginx websocket laravel-forge


    【解决方案1】:

    在注册一个新的推送者帐户并清除配置缓存后,终于可以正常工作了。有时需要大声说出来才能弄清楚

    【讨论】:

      猜你喜欢
      • 2021-10-19
      • 1970-01-01
      • 2021-04-25
      • 2013-08-22
      • 2019-08-14
      • 2021-01-27
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多