[英]NGINX not routing to the net core Project (with port other than 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 核心項目(項目 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") ;
}
請幫忙
無法訪問此站點 連接已重置。
此消息出現在 b/c 端口 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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.