c# - Yarp.ReverseProxy 后面的 SignalR 导致超时导致服务器不响应
问题描述
我已经使用以下代码实现了一个 yarp.reverse 代理服务器:
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpProxy();
services.AddCors(options =>
{
options.AddPolicy("customPolicy", builder =>
{
builder.AllowAnyOrigin();
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpProxy httpProxy)
{
// Configure our own HttpMessageInvoker for outbound calls for proxy operations
var httpClient = new HttpMessageInvoker(new SocketsHttpHandler()
{
UseProxy = false,
AllowAutoRedirect = false,
AutomaticDecompression = DecompressionMethods.None,
UseCookies = false
});
// Setup our own request transform class
var transformer = new CustomTransformer(); // or HttpTransformer.Default;
var requestOptions = new RequestProxyOptions { Timeout = TimeSpan.FromSeconds(100) };
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.Map("/{**catch-all}", async httpContext =>
{
httpContext.Request.Headers["Connection"] = "upgrade";
await httpProxy.ProxyAsync(httpContext, "http://192.168.178.80:5000", httpClient, requestOptions, transformer);
var errorFeature = httpContext.Features.Get<IProxyErrorFeature>();
save_log(httpContext.Request.Path, "/", "http://192.168.178.80:5000" + httpContext.Request.Path, "3");
// Check if the proxy operation was successful
if (errorFeature != null)
{
var error = errorFeature.Error;
var exception = errorFeature.Exception;
}
});
});
}
在另一个应用程序中,一个 SignalR 服务器遵循此示例:https ://docs.microsoft.com/en-GB/aspnet/core/tutorials/signalr?view=aspnetcore-5.0&tabs=visual-studio
代理服务器工作并将请求转发到 signalR 服务器。但是 signalR 客户端无法连接到 signalR 服务器。我总是因为错误而断开连接
错误:服务器超时未收到来自服务器的消息。
在 Java 脚本控制台中。但 SSE 已连接,您可以在以下浏览器状态报告中看到:
signalr.js:2156 [2021-03-25T13:19:29.970Z] 信息:SSE 连接到 https://localhost:44318/chatHub?id=IqKD6P0NsUY9Is6OSrMusQ
问题似乎出在代理服务器上,因为如果我直接调用该站点,它就可以工作。有人知道我的代理有什么问题以及如何解决吗?
解决方案
推荐阅读
- r - 使用 stargazer 在 Rmarkdown beamer 中绘制表格
- python - 如何输入 JSON 文件
- tensorflow - Tensorflow Object Detection API Faster-RCNN 收敛但检测不准确
- ios - UIPage 控件的画外音或可访问性
- aws-glue - 如果大小 >1MB,AWS 爬虫无法对 S3 中的文件类型存储进行分类
- javascript - 如何从输入值中删除数字?
- vba - 如何删除单词中以某个单词开头的每一行?
- javascript - 连接和缩小后如何使用require js文件
- angular - Angular Routing: Should I use more than one routing file?
- angular - 我无法在选择选项中设置默认值(Angular)