Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有信号器和动态DNS解析的NGINX反向代理_C#_.net_Nginx_Dns_Signalr - Fatal编程技术网

C# 具有信号器和动态DNS解析的NGINX反向代理

C# 具有信号器和动态DNS解析的NGINX反向代理,c#,.net,nginx,dns,signalr,C#,.net,Nginx,Dns,Signalr,我有一个内置于C#(.NET Core 3.1)的微服务,我使用SignalR在前端应用程序和该微服务提供的功能之间进行实时通信。 在堆栈中,我们有另一个容器,它将NGINX作为web服务器(用于前端应用程序)和反向代理(用于提供对服务的访问)运行 我在microsoft文档中找到了这篇文章(),然后配置了路由: location /route/to/signalR/endpoint { proxy_pass https://microservice-name:3000/route/to

我有一个内置于C#(.NET Core 3.1)的微服务,我使用SignalR在前端应用程序和该微服务提供的功能之间进行实时通信。 在堆栈中,我们有另一个容器,它将NGINX作为web服务器(用于前端应用程序)和反向代理(用于提供对服务的访问)运行

我在microsoft文档中找到了这篇文章(),然后配置了路由:

location /route/to/signalR/endpoint {
    proxy_pass https://microservice-name:3000/route/to/signalR/endpoint;

    add_header Access-Control-Allow-Origin *;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_cache off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
到目前为止,一切都很好

但随后出现了一个缺陷,一段时间后,nginx开始对收到的所有请求做出404响应。发生这种情况是因为我们的微服务容器可能会停止(由于Healthckek),然后再次启动,并且它可能具有不同的IP地址

为了解决这个问题,我遵循了本文的说明:,这对于不使用信号器的端点来说效果很好

#BEFORE
location /some/common/route
{
    proxy_pass https://microservice-name:3000/some/common/route;;
    add_header Access-Control-Allow-Origin *;
}

#AFTER
location /some/common/route
{
    set $someCommonRoute https://microservice-name:3000/some/common/route;
    proxy_pass $someCommonRoute;
    add_header Access-Control-Allow-Origin *;
}
我希望这也能在信号机路线中使用,使用以下配置:

location /route/to/signalR/endpoint {
    set $routeToSignalREndpoint https://microservice-name:3000/route/to/signalR/endpoint;
    proxy_pass $routeToSignalREndpoint;

    add_header Access-Control-Allow-Origin *;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_cache off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
但是,这足以使服务器在此路由中返回错误400(错误请求)。
有人知道为什么会这样吗?如何配置NGINX以使用signar和动态DNS解析?

您将收到一个响应,这意味着您正在查找主机,但可能无法获取其余路由。错误的请求通常意味着服务器不喜欢请求中的参数。一个原因可能是默认浏览器。当您使用错误的浏览器时,某些服务器会拒绝连接。因此,在c#请求中,您可能需要添加UserAgent。请参阅:如果发送了错误类型的协议:HTTP或HTTPS,也可能会收到错误的请求。当我将硬编码url作为“代理传递”的参数传递时,一切正常。因此,这不是http/https的问题,也不是与浏览器相关的问题。此问题仅在代理传递通过变量使用url时发生。您是管理员吗?在VS中运行时,您没有管理员权限,除非您右键单击快捷方式并选择“以管理员身份运行”来启动VS。您可能还存在域问题。请与您的MIS组联系,查看域是否正确。