Соединение концентратора SignalR не удалось успешно запустить из-за ошибки «Ошибка: произошла ошибка с транспортом».

#asp.net-core #nginx #signalr

Вопрос:

У меня возникли проблемы с подключением к серверу 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;
  }
 

Ответ №1:

Из документации Microsoft ниже приведены минимальные необходимые параметры для включения WebSockets в Nginx

 # 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