beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.08k stars 628 forks source link

Trouble setting up websockets on GCP flex environment #579

Closed ruchit-parikh closed 9 months ago

ruchit-parikh commented 4 years ago

I am using Laravel 6 and trying to setup websocket on Google Cloud Flex Environment. This is my nginx-app.conf file

location /ws {
    proxy_pass         "http://127.0.0.1:6001";
    proxy_http_version  1.1;
    proxy_set_header    Upgrade $http_upgrade;
    proxy_set_header    Connection "upgrade";
    proxy_set_header    Host $http_host;
    proxy_set_header    X-Real-IP $remote_addr;
}

location / {
  # try to serve files directly, fallback to the front controller
    try_files $uri /$front_controller_file$is_args$args;
}

I am setting this values in websockets

'apps' => [
        [
            'id' => env('PUSHER_APP_ID'),
            'name' => env('APP_NAME'),
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'path' => env('PUSHER_APP_PATH'),
            'capacity' => null,
            'enable_client_messages' => false,
            'enable_statistics' => true,
        ],
    ],

Also my app.yaml

runtime: php
env: flex

runtime_config:
  document_root: public

service: orders

skip_files:
  - .env

#only for testing purpose. 
manual_scaling:
  instances: 1

env_variables:
  APP_NAME: "Havn"
  APP_KEY: SOME KEY
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  CACHE_DRIVER: database
  DB_HOST: localhost
  DB_CONNECTION: mysql
  DB_DATABASE: "havn_orders"
  DB_USERNAME: USERNAME
  DB_PASSWORD: PASSWORD
  DB_SOCKET: DBSOCKET
  APP_ENV: production
  APP_DEBUG: false
  PUSHER_APP_ID: JFODKKAM832LS
  PUSHER_APP_KEY: UPOdToTezwmLiINUpO67RECto36tCFp2pwCASuZ8WeXvJZ8B2UhTxifA8EwwPY8m
  PUSHER_APP_SECRET: 8efYDWMgqE1vHgeZ05Fmt2WIO9FwWHcuxBXIBNWwNn9SsdZbcY5XfoZXD08d7Xhu
  PUSHER_APP_CLUSTER: mt1
  LARAVEL_WEBSOCKETS_PORT: 6001
  PUSHER_SCHEME: http
  PUSHER_HOST: orders-dot-consumers-public-gateway.nw.r.appspot.com
  PUSHER_PORT: 6001
  QUEUE_DRIVER: database
  WEBSOCKET_BROADCAST_HOST: orders-dot-consumers-public-gateway.nw.r.appspot.com

beta_settings:
  cloud_sql_instances: INSTANCE_ID

network:
  session_affinity: true

I have also open port 6001 on firewall. Can you please help me with this? We are stuck with this problem from last month! Everything works on local machine though trouble setting up on google cloud.

jttully commented 4 years ago

I'm unsure if this is the case on App Engine Flex as it is in other managed GCP services, but services like GKE require you to only communicate via ingresses if you use port 80 or port 443. If that is the case on App Engine Flex as it is on GKE ingress, then I would recommend you try adapting the "Same location for websockets and web contents" nginx block from the beyondcode documentation.

Using that nginx block with the traffic type map has been the best way of hosting websockets on GKE without differentiating url path to /ws and still routing that modified path over 443.

ruchit-parikh commented 4 years ago

Thanks but can you please provide nginx file for that ? I dont know how to write that! Your help is really appriciated!!!!!