问题
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;
}
}
this works http://10.XX.XX.XX/ and shows the page of .net Core (Project A)
but
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.
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"
}
} } }
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") ;
}
Please help
回答1:
This site can’t be reached The connection was reset.
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;
}
}
来源:https://stackoverflow.com/questions/58095466/nginx-not-routing-to-the-net-core-project-with-port-other-than-80