NGINX 未路由到网络核心项目(使用 80 以外的端口)

NGINX 未路由到网络核心项目(使用 80 以外的端口)

/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 core 项目(项目 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") ;
}

请帮忙

答案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;
}
}

相关内容