ASP .net core Web API 只处理本地请求

ASP .netcore WebAPI only processing local requests

您好,我在本地/来自同一 IP 的请求上返回 200,但是当我使用热点我的手机 phone 更改 IP 并发出请求时出现以下错误

HTTPConnectionPool(host={myIPAddress}, port=80): Max retries exceeded ..... Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'

program.cs 文件

public static void Main(string[] args)
{
    CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseUrls("http://0.0.0.0:5000/")
        .UseKestrel(serverOptions =>
        {
            //Set properties and call methods on serverOptions
            serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
            serverOptions.Limits.MaxConcurrentConnections = 100;
            serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
            serverOptions.Limits.MaxRequestBodySize = 10 * 1024;
            serverOptions.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(1);
        });
}

NGINX - sites-available/default

server {
listen 80;
listen [::]:80;
server_name   HFTest;

location / {
    proxy_pass         http://localhost:5000; **#edited as per comments**
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

端口状态 - sudo netstat -tulpn | grep LISTEN

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      635/nginx: master p
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      628/sshd
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      2048/API/HFTest

对接下来要解决的问题有什么想法吗?

谢谢

编辑:

请求-在python

scopes = 'openid'
url='http://{IPAddress}:80/connect/token'

session = OAuth2Session(clientID,clientSecret, scope=scopes)
token = session.fetch_access_token(url,verify=False)

endpoint = "http://{IPAddress}/{endpoint}"

headers = {"Authorization": "Bearer %s" % token['access_token'],"Accept": "text/xml"}

session = requests.Session()

response = session.request("GET",endpoint,headers=headers,verify = False)
print(response.status_code)
print(response.text)

你的nginx配置中的upstream service ip需要是一个真实的ip地址。可以试试localhost ip如下

…
location / {
    proxy_pass         http://127.0.0.1:5000;
…