502坏网关在Ubuntu 20.04上的NGINX上运行ASP.NET Core 5网站



不确定问题是什么:

502 Bad Gateway
nginx/1.18.0 (Ubuntu)

来自nginx日志:

2021/11/05 21:59:21 [error] 59385#59385: *1 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5004/", host: "mdomain.com"

我的网站nginx-config:

server {
listen 80;
listen [::]:80;
server_name mydomain.com www.mydomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name mydomain.com www.mydomain.com;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
root /var/www/mydomain.com;
large_client_header_buffers 4 16k;
location / {
proxy_pass http://localhost:5004;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_buffer_size          128k;
proxy_buffers              4 256k;
proxy_busy_buffers_size    256k;
}
location ~ /.well-known {
root /var/www/mydomain.com;
}
}

我的ASP.NET核心5站点:

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls("http://localhost:5004");
});

对于有同样问题的人,我在ASP.NET项目的url中使用了通配符,它很有效。

UseUrls("http://*:5004"(;

最新更新