【问题标题】:Error during WebSocket handshake: Unexpected response code: 502 when connecting on azure with ocelot gatewayWebSocket 握手期间出错:意外的响应代码:在 azure 上与 ocelot 网关连接时出现 502
【发布时间】:2021-03-01 21:31:18
【问题描述】:

我在我的应用程序中使用 signalR,在 Azure 门户上上传 ocelot 网关时出错

我的ts代码

this.hubConnection = new signalR.HubConnectionBuilder()
        .withUrl("https://url.azurewebsites.net/gatewayOcelot/notification", {
            skipNegotiation: true,
            transport: signalR.HttpTransportType.WebSockets
        })
        .build();

而豹猫路线是

{
  "UpstreamPathTemplate": "/gatewayOcelot/{url}",
  "UpstreamHttpMethod": [ "Get", "Put", "Delete", "Post", "Patch", "OPTIONS" ],
  "DownstreamPathTemplate": "/api/{url}",
  "DownstreamScheme": "wss",
  "DownstreamHostAndPorts": [
    {
      "Host": "apiURL.com",
      "Port": 443
    }
  ],
  "HttpHandlerOptions": {
    "AllowAutoRedirect": true
  }
},

启动代码

 app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
          
            endpoints.MapHub<NotificationHub>("/api/notification");
        });

得到错误

WebSocket connection to 'wss://url.azurewebsites.net/gatewayOcelot/notification' failed: Error during WebSocket handshake: Unexpected response code: 502

【问题讨论】:

    标签: azure websocket signalr ocelot


    【解决方案1】:

    仔细检查一下:需要在Ocelot上配置WebSocket:

     Configure(app =>
    {
        app.UseWebSockets();
        app.UseOcelot().Wait();
    })
    

    在 ocelot.json 中

    {
         "DownstreamPathTemplate": "/ws",
         "UpstreamPathTemplate": "/",
         "DownstreamScheme": "ws",
         "DownstreamHostAndPorts": [
             {
                 "Host": "localhost",
                 "Port": 5001
             }
         ],
     }
    

    https://ocelot.readthedocs.io/en/latest/features/websockets.html#:~:text=Ocelot%20supports%20proxying%20websockets%20with,your%20application%20to%20use%20WebSockets.

    【讨论】:

    • 我已经在启动时添加了 ocelot public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseWebSockets(); app.UseOcelot().Wait(); }
    • 那么,您应该诊断并解决问题 => 应用服务计划的可用性和性能。 (在 IIS 级别发生 502 错误)
    猜你喜欢
    • 1970-01-01
    • 2019-11-26
    • 2014-05-02
    • 2020-09-19
    • 1970-01-01
    • 2020-08-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多