NGINX没有路由到网络核心项目(端口不是80) [英] NGINX not routing to the net core Project (with port other than 80)
问题描述
我在/etc/nginx/sites-available文件夹的默认配置文件中包含以下内容
I have the following in the default config file in the /etc/nginx/sites-available folder
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)
this works http://10.XX.XX.XX/ and shows the page of .net Core (Project A)
但是
这不起作用 http://10.XX.XX.XX:81 /api/facultyinterestitems 并且不显示另一个正在运行的.net核心项目(项目B)的页面,而是显示一个错误页面
This does not work http://10.XX.XX.XX:81/api/facultyinterestitems and does not show the page of another running .net core project (Project B) instead shows an error page
无法访问此站点连接已重置.
This site can’t be reached The connection was reset.
这是项目B上的LaunchSettings.json
here is the LaunchSettings.json on Project B
{
"$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
and Program.cs of Project B
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") ;
}
请帮助
推荐答案
无法访问此站点连接已重置.
This site can’t be reached The connection was reset.
此消息显示为b/c,端口81在我的组织中被阻止.
This message was appearing b/c the port 81 was blocked in my organization.
第二,也可以通过在配置文件中使用不同的服务器名称来解决此问题.因此默认文件将变成这样
Secondly, the problem can also be resolved by using different server names in the config file. so the default file will become like this
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;
}
}
这篇关于NGINX没有路由到网络核心项目(端口不是80)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!