【问题标题】:How to use laravel-websockets with nginx reverse proxy on google app engine?如何在谷歌应用引擎上使用 laravel-websockets 和 nginx 反向代理?
【发布时间】:2019-04-23 15:22:47
【问题描述】:

我正在尝试将laravel-websockets 部署到谷歌应用引擎服务中,并且不管理 ssl 证书。应用程序引擎“google frontend”只会将端口 80 和 443 转发到在端口 8080 中侦听的自定义用户 nginx.conf 文件。因此,部署后没有错误,google stackdriver 日志显示 websocket 服务正在接受连接,但是前端服务没有显示任何东西,没有错误,也没有成功。那么我错过了什么?

目前该服务的 nginx.conf 是:

daemon off;

user  root;
worker_processes  auto;
error_log /dev/stderr info;

events {
    worker_connections  4096;
}

http {
    access_log /dev/stdout;

    server {
        listen 8080;

        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;
        }
    }
}

还有我的 app.yaml 文件:

runtime: custom
env: flex

service: websockets

manual_scaling:
  instances: 1

resources:
  cpu: 2
  memory_gb: 2
  disk_size_gb: 10

runtime_config:
  document_root: public
  enable_stackdriver_integration: true

readiness_check:
  app_start_timeout_sec: 1800

env_variables:
  // all basic laravel env here plus:

  BROADCAST_DRIVER: pusher

  PUSHER_APP_ID: testing
  PUSHER_APP_KEY: testing
  PUSHER_APP_SECRET: testing

我在 broadcast.php 文件中的推送器配置是

'pusher' => [
    'driver'  => 'pusher',
    'key'     => env('PUSHER_APP_KEY'),
    'secret'  => env('PUSHER_APP_SECRET'),
    'app_id'  => env('PUSHER_APP_ID'),
    'options' => [
        'host'      => 'my-websockets-service-generated-domain.appspot.com',
        'port'      => '443',
        'scheme'    => 'https',
        'encrypted' => true
    ],
],

最后是我在客户端的设置:

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

const echo = new Echo({
  authEndpoint: 'my-backend-service-generated-domain.appspot.com/broadcasting/auth',
  broadcaster: 'pusher',
  key: 'testing',
  httpHost: 'my-websockets-service-generated-domain.appspot.com',
  httpsPort: 443,
  disableStats: true,
  encrypted: true
})

谷歌堆栈驱动程序日志:

【问题讨论】:

    标签: laravel google-app-engine nginx websocket


    【解决方案1】:

    我明白了!在客户端的 Echo 设置中,我需要使用 wsHost 并更新 wsPortwssPort 以使用 80 和 443,nginx 反向代理会将其代理到 6001

    broadcaster: 'pusher',
    key: 'testing',
    wsHost: 'my-websockets-service-generated-domain.appspot.com',
    wsPort: 80,
    wssPort: 443,
    disableStats: true,
    encrypted: true
    

    【讨论】:

    • 您是否将您的 broadcast.php 设置为 https 和 443 或切换到 http 和 6001?
    • @Munsterlander 查看版本控制,它是 443,但这个项目不再活跃,所以我无能为力。
    • 没问题。我遇到了类似的问题并试图解决这个问题。
    • @Munsterlander 你最后成功了吗? :)
    猜你喜欢
    • 2011-08-09
    • 2013-02-18
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2011-08-03
    • 1970-01-01
    相关资源
    最近更新 更多