Моя конфигурация следующая:
Cloudflare Ngnix + Mysql. Net Core 2.2. MVC Приложение
Иногда я получаю следующие ошибки, когда мой сервер занят (200 человек в день). Где моя вина?
"Ошибка подключения WebSocket к удаленному хосту: ошибка во время рукопожатия WebSocket : Неожиданный код ответа: 404 "" Ошибка: не удалось запустить транспорт 'WebSockets': Ошибка: произошла ошибка с транспортом. " «Ошибка: соединение разорвано с ошибкой« Ошибка ».» «POST https://x.com/ahub?id=QQMZ6v3PHzl9srr5WX0fAw 400» «Ошибка: сервер вернул ошибку рукопожатия: рукопожатие было отменено.»
Конфигурация Ngnix:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name a.com;
root /var/www/App;
# SSL
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
# logging
access_log /var/log/nginx/a.com.access.log;
error_log /var/log/nginx/a.com.error.log warn;
# reverse proxy
location / {
proxy_pass http://localhost:5089;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
#Error pages.
error_page 503 /maintenance.html;
location = /maintenance.html {
root /var/www/MaintenanceOn/;
}
#SignalR Hubs
location /ahub {
proxy_pass http://localhost:5089/exchangehub;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /bhub {
proxy_pass http://localhost:5089/coinhub;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /chub {
proxy_pass http://localhost:5089/bisthub;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /dhub {
proxy_pass http://localhost:5089/goldhub;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /ehub {
proxy_pass http://localhost:5089/parityhub;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name www.a.com;
return 301 https://a.com;
}
Startup.cs
Настройка
app.UseCookiePolicy();
app.UseSignalR(routes =>
{
routes.MapHub<aHub>("/ahub", options =>
{
//options.TransportMaxBufferSize = 0;
//options.ApplicationMaxBufferSize = 0;
});
routes.MapHub<bHub>("/bhub", options =>
{
//options.TransportMaxBufferSize = 0;
//options.ApplicationMaxBufferSize = 0;
});
routes.MapHub<cHub>("/chub", options =>
{
//options.TransportMaxBufferSize = 0;
//options.ApplicationMaxBufferSize = 0;
});
routes.MapHub<dHub>("/dhub", options =>
{
//options.TransportMaxBufferSize = 0;
//options.ApplicationMaxBufferSize = 0;
});
routes.MapHub<eHub>("/ehub", options =>
{
//options.TransportMaxBufferSize = 0;
//options.ApplicationMaxBufferSize = 0;
});
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "mobile",
template: "{area:exists}/{controller=Home}/{action=Index}");
//Default Route
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Настройка службы
services.AddSignalR(options=>{
options.EnableDetailedErrors = true;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
JS
var connectionExchange = new signalR.HubConnectionBuilder()
.withUrl("/ahub",{transports: ['websocket']}).withAutomaticReconnect().build();
var connectionParity = new signalR.HubConnectionBuilder()
.withUrl("/bhub",{transports: ['websocket']}).withAutomaticReconnect().build();
ar connectionCoin = new signalR.HubConnectionBuilder()
.withUrl("/chub",{transports: ['websocket']}).withAutomaticReconnect().build();
var connectionBist = new signalR.HubConnectionBuilder()
.withUrl("/dhub",{transports: ['websocket']}).withAutomaticReconnect().build();
var connectionGold = new signalR.HubConnectionBuilder()
.withUrl("/ehub",{transports: ['websocket']}).withAutomaticReconnect().build();