WebSocket connection failed when protocol is HTTP/2

I use gRPC and WebSocket in a same port.
It use Content-Type header check

then I deploy on Koyeb. its only select one of HTTP or HTTP/2

on Nginx i use this profile

#PROXY-START/
underscores_in_headers on;
 
location ^~ / {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
 
    add_header X-Cache $upstream_cache_status;
}
 
location ^~ /proto.MyProto {
    grpc_pass grpc://127.0.0.1:8000;
    grpc_read_timeout 300d;
    grpc_send_timeout 300d;
    grpc_socket_keepalive on;
    grpc_set_header Host $host;
    grpc_set_header X-Real-IP $remote_addr;
    grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    grpc_set_header REMOTE-HOST $remote_addr;
    access_log off;
}
 
#PROXY-END/

I dont know how to let koyeb work.

Hey,

You can’t use both websockets and grpc on the same port.

I see that you want two paths:

  • / → websockets
  • /proto.MyProto → grpc

You could change your app such that it listens on two ports:

  • Port A (e.g. 8000): websocket handler
  • Port B (e.g. 8001): grpc handler

Then, you can define your service such that:

  • Route /proto.MyProto is mapped to port A (8001)
  • Route / is mapped to port B (8000)

Let me know if that helps!