asp.net-core - 502 Bad Gateway 在 Ubuntu 20.04 上的 NGINX 上运行 ASP .NET Core 5 站点

标签 asp.net-core ubuntu nginx

不确定是什么问题:

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 配置:
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 core 5 站点:
public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.UseUrls("http://localhost:5004");
        });

最佳答案

对于任何有同样问题的人,我在我的 ASP .NET 项目的 url 中使用了通配符,它​​可以工作。
webBuilder.UseUrls("http://*:5004");

关于asp.net-core - 502 Bad Gateway 在 Ubuntu 20.04 上的 NGINX 上运行 ASP .NET Core 5 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69859771/

相关文章:

java - 重写规则附加 webapp 上下文路径与 <spring :url> and <c:url> taglibs 冲突

php - Google 拒绝 postfix 发送的邮件 (550-5.7.1)

nginx - 配置 nginx 重写所有路径上的哈希值

asp.net-web-api - WebAPI 中是否需要 ValidateAntiForgeryToken

azure - 如何从 vNext Build 运行 Azure WebJob?

python - 在ubuntu上正确使用pip3安装tflearn

python-2.7 - 使用 ubuntu 安装 Python 库

c# - .NET CORE依赖注入(inject)将参数传递给构造函数

asp.net-web-api - 在 ASP.NET Core RC2 中使用 HttpConfiguration

linux - 如何将命令的输出通过管道传输到 Linux 上的文件