【问题标题】:502 Bad Gateway running ASP .NET Core 5 site on NGINX on Ubuntu 20.04502 Bad Gateway 在 Ubuntu 20.04 上的 NGINX 上运行 ASP .NET Core 5 站点
【发布时间】:2021-12-19 21:27:20
【问题描述】:

不确定是什么问题:

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-core ubuntu nginx


    【解决方案1】:

    对于任何有同样问题的人,我在我的 ASP .NET 项目的 url 中使用了通配符,它​​可以工作。

    webBuilder.UseUrls("http://*:5004");

    【讨论】:

      猜你喜欢
      • 2019-11-25
      • 2017-08-20
      • 2020-05-13
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2017-04-18
      • 2017-12-12
      相关资源
      最近更新 更多