【问题标题】:NGINX not routing to the net core Project (with port other than 80)NGINX 没有路由到 net core 项目(端口不是 80)
【发布时间】:2020-01-25 11:21:24
【问题描述】:

我在 /etc/nginx/sites-available 文件夹的默认配置文件中有以下内容

server {
listen        80;   
location / {
    proxy_pass         http://10.XX.XX.XX:5000;
    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_cache_bypass $http_upgrade;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen        81;   
 location / {
    proxy_pass         http://10.XX.XX.XX:5050;
    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_cache_bypass $http_upgrade;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
}

}

这适用于http://10.XX.XX.XX/,并显示了.net Core(项目A)的页面

但是

这不起作用http://10.XX.XX.XX:81/api/facultyinterestitems 并且不显示另一个正在运行的 .net 核心项目(项目 B)的页面,而是显示错误页面

无法访问此站点连接已重置。

这是项目 B 上的 LaunchSettings.json

{
 "$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false, 
"anonymousAuthentication": true, 
"iisExpress": {
  "applicationUrl": "http://10.XX.XX.XX:53199",
  "sslPort": 44378
}  },
 "profiles": {
"IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "launchUrl": "api/FacultyInterestItems",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},
"FacultyAPI": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "api/FacultyInterestItems",
  "applicationUrl": "http://10.XX.XX.XX:5050",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}  }    }

和项目 B 的 Program.cs

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

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>().UseUrls("http://10.XX.X.XX:5050") ;
}

请帮忙

【问题讨论】:

    标签: nginx asp.net-core webserver port config


    【解决方案1】:

    无法访问此站点连接已重置。

    此消息出现在我的组织中,因为端口 81 被阻止。

    其次,该问题也可以通过在配置文件中使用不同的服务器名称来解决。所以默认文件会变成这个样子

     server {
    listen 80;
    server_name keywordsapi.test.kfupm.edu.sa;
    location / {
        proxy_pass http://localhost:5000;
        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;
    }
    }
    server {
    listen 80;
    server_name keywords.test.kfupm.edu.sa;
    location / {
        proxy_pass http://localhost:5050;
        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;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-03
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 2019-04-24
      • 1970-01-01
      相关资源
      最近更新 更多