gpt4 book ai didi

nginx - Nginx 背后的 SignalR - 获得 200 响应而不是 websocket 升级

转载 作者:行者123 更新时间:2023-12-04 17:41:53 30 4
gpt4 key购买 nike

我正在使用 Nginx v1.15.5 将 ASP.NET Core 应用程序从 Windows Server 迁移到 Ubuntu,并且我一直在努力让 SignalR 正常工作。 websocket 连接不断获得 200 返回码而不是升级。该应用程序的所有其他方面都有效。

在带有 IIS、IIS Express 和本地 Kestrel 开发服务器的 Windows 上一切正常,所以我猜我在 Nginx 代理配置中遗漏了一些东西。

我已经尝试了下面引用部分中列出的所有内容。下面是事情的当前状态(启动和我网站的 Nginx 配置)。日志看起来都像下面列出的那些。

该站点是公开的,因此您可以使用开发工具对其进行测试以查看请求/响应。

Site: https://my.doxm.app/
Login ID: fix@me.please
Password: P@ssword1

SignalR 连接在登录后立即启动。

任何帮助,将不胜感激。

在 Startup.cs 中
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataService dataService)
{
DataService = dataService;
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
//app.UseHttpsRedirection();
}

ConfigureStaticFiles(app);

app.UseCookiePolicy();

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

app.UseAuthentication();

app.UseSignalR(routes =>
{
routes.MapHub<BrowserSocketHub>("/BrowserHub", options =>
{
options.ApplicationMaxBufferSize = 500000;
options.TransportMaxBufferSize = 500000;
});
routes.MapHub<DeviceSocketHub>("/DeviceHub", options =>
{
options.ApplicationMaxBufferSize = 500000;
options.TransportMaxBufferSize = 500000;
});
routes.MapHub<RCDeviceSocketHub>("/RCDeviceHub");
routes.MapHub<RCBrowserSocketHub>("/RCBrowserHub");
});
app.UseMvcWithDefaultRoute();
dataService.SetAllMachinesNotOnline();
dataService.CleanupEmptyOrganizations();
dataService.CleanupOldRecords();
}

Nginx 站点配置
server {
listen 80;
server_name my.doxm.app *.my.doxm.app;
location / {
proxy_pass http://localhost:5000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_cache_bypass $http_upgrade;
}

location /BrowserHub {
proxy_pass http://localhost:5000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_cache_bypass $http_upgrade;
}


# Other locations will go here once I get the above one working.

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my.doxm.app/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my.doxm.app/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

/etc/nginx/proxy_params 的内容
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

引用:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2

SignalR in ASP.NET Core behind Nginx

https://kimsereyblog.blogspot.com/2018/07/signalr-with-asp-net-core.html

Asp.Net Core 2 SignalR Ubuntu Xamarin Android

https://www.nginx.com/blog/websocket-nginx/

http://nginx.org/en/docs/http/websocket.html

日志
2019/01/09 14:05:24 [alert] 24344#24344: *74 open socket #3 left in connection 5
2019/01/09 14:05:24 [alert] 24344#24344: *79 open socket #13 left in connection 8
2019/01/09 14:05:24 [alert] 24344#24344: aborting
2019/01/09 14:11:20 [alert] 24395#24395: *200 open socket #13 left in connection 4
2019/01/09 14:11:20 [alert] 24395#24395: *195 open socket #3 left in connection 15
2019/01/09 14:11:20 [alert] 24395#24395: aborting
2019/01/09 14:26:12 [alert] 24845#24845: *1 open socket #3 left in connection 3
2019/01/09 14:26:12 [alert] 24845#24845: *6 open socket #13 left in connection 4
2019/01/09 14:26:12 [alert] 24845#24845: aborting
2019/01/09 14:36:49 [alert] 25082#25082: *19 open socket #3 left in connection 3
2019/01/09 14:36:49 [alert] 25082#25082: *24 open socket #13 left in connection 4
2019/01/09 14:36:49 [alert] 25082#25082: aborting
2019/01/09 14:48:06 [alert] 26806#26806: *62 open socket #13 left in connection 3
2019/01/09 14:48:06 [alert] 26806#26806: *57 open socket #3 left in connection 4
2019/01/09 14:48:06 [alert] 26806#26806: aborting
2019/01/09 14:49:12 [alert] 26933#26933: *1 open socket #3 left in connection 3
2019/01/09 14:49:12 [alert] 26933#26933: *5 open socket #14 left in connection 5
2019/01/09 14:49:12 [alert] 26933#26933: aborting

最佳答案

该问题最终与 Nginx 无关。 System.Net.WebSockets.WebSocketProtocol.dll 的 DLL 版本不匹配。 WinSCP 显然没有在部署时覆盖它。我原以为会有错误响应,但在异常发生后它仍然发回 200。

关于nginx - Nginx 背后的 SignalR - 获得 200 响应而不是 websocket 升级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54121479/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com