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

5f0d552i  于 2022-11-22  发布在  Nginx
关注(0)|答案(1)|浏览(211)

不确定是什么问题:

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核心5站点:

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

qoefvg9y1#

对于任何有同样问题的人,我在ASP.NET项目中的URL中使用了通配符,它起作用了。
(“);

相关问题