无法通过nginx连接signalR

gab6jxml  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(190)

我正在学习如何使用docker-compose来部署应用程序。我有一个asp.net核心Web API,它有signalR端点。当我在主机上运行时,它工作得很好。但是在我运行nginx之后,我无法连接到它,但是API仍然工作正常。任何建议将不胜感激。
我的docker-compose文件:

version: "3.7"

services:
  proxy:
    build: ./nginx
    ports:
      - 80:80
    depends_on:
      - app1
      - app2
  app1:
    build: ./API
    ports:
      - 8080:80
    working_dir: /app
    environment:
      DATABASE_URL: postgres://postgres:postgrespw@127.0.0.1:5432/datingapp
      REDIS_HOST: redis
      REDIS_PORT: 6379
    depends_on:
      - postgres
      - redis
  app2:
    build: ./API
    ports:
      - 8081:80
    working_dir: /app
    environment:
      DATABASE_URL: postgres://postgres:postgrespw@127.0.0.1:5432/datingapp
      REDIS_HOST: redis
      REDIS_PORT: 6379
    depends_on:
      - postgres
      - redis
  redis:
    image: redis:6.2.6-alpine
    ports:
      - 6379:6379
  postgres:
    image: postgres:latest
    environment:
      POSTGRES_PASSWORD: postgrespw

字符串
我的nginx.conf

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  upstream backend {
    server api1:80;
    server api2:80;
  }

  server {
    listen 80;
    location / {
      proxy_pass http://backend;
      proxy_set_header Host $host;
    }
  }
}


WebSocket错误:x1c 0d1x的数据
nginx内部日志:


后端服务器日志之一:

xeufq47z

xeufq47z1#

如果需要从头开始创建WebSocket连接,则必须自己处理握手过程。创建初始HTTP/1.1会话后,您需要通过向标准请求添加Upgrade和Connection标头来请求升级,如下所示:联系方式:升级升级:WebSocket
像下面这样修改你的nginx.conf文件。

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  upstream backend {
    server api1:80;
    server api2:80;
  }

  server {
    listen 80;
    location / {
      proxy_pass http://backend/hubs/presence;
      proxy_set_header Host $host;
    }
    location /hubs/presence{
        proxy_pass http://backend;
        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;
    }

  }
}

字符串

相关问题