【问题标题】:SignalR HubConnection failed to start successfully because of error 'Error: There was an error with the transport.'由于错误“错误:传输出现错误”,SignalR HubConnection 未能成功启动。
【发布时间】:2021-08-16 19:38:07
【问题描述】:

我在连接到 signalR 服务器时遇到问题。我在 nginx 上的初始设置是


location /notificationHub/ {
    rewrite ^/notificationHub/?(.*) /notificationHub/$1 break;
    proxy_pass http://api_beta_server;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }

【问题讨论】:

    标签: asp.net-core nginx signalr


    【解决方案1】:

    来自 microsoft 文档,以下是在 Nginx 上启用 WebSockets 所需的最低设置

    # add this at the top of ninx config
    map $http_connection $connection_upgrade {
        "~*Upgrade" $http_connection;
        default keep-alive;
    }
    
    # Configure the SignalR Endpoint inside server setting
    location /hubroute {
          # App server url
          proxy_pass http://localhost:5000;
    
          # Configuration for WebSockets
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
          proxy_cache off;
          # WebSockets were implemented after http/1.0
          proxy_http_version 1.1;
    
          # Configuration for ServerSentEvents
          proxy_buffering off;
    
          # Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds
          proxy_read_timeout 100s;
    
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }
    full documentation is on SignalR [documentaion][1]
      [1]: https://docs.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-5.0
    

    【讨论】:

      猜你喜欢
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      相关资源
      最近更新 更多