如何在Google App Engine上将laravel-websockets与nginx反向代理一起使用?

时间:2019-04-23 15:22:48

标签: laravel google-app-engine nginx websocket

我正在尝试将laravel-websockets部署到Google App Engine服务中,并且不管理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
})

google stackdriver日志:

google stackdriver logs

1 个答案:

答案 0 :(得分:0)

我知道了!在客户端的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