【问题标题】:Asp.net Core Large File Upload in Nginx connection timeout issueNginx 连接超时问题中的 Asp.net Core 大文件上传
【发布时间】:2019-05-15 11:02:07
【问题描述】:

我在 Digital Ocean 10$ Ubuntu Droplet 中运行 Asp.net 核心应用程序,上传多个或大文件时出现问题,一段时间后连接断开,不知道该怎么办这是我的代理设置:

    proxy_redirect off;
    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;
    client_max_body_size 1000m;
    client_body_buffer_size 1000m;
    uwsgi_read_timeout     1000s;
    proxy_connect_timeout 90;
    proxy_send_timeout 100;
    proxy_read_timeout 100s;
    fastcgi_send_timeout 1000s;
    fastcgi_read_timeout 1000s;
    proxy_buffers 32 4k;

【问题讨论】:

  • 你试过查看你的日志文件吗?
  • 增加你的proxy_send_timeoutproxy_read_timeout
  • 感谢回复戳,在日志中我有错误“连接到上游时连接被拒绝”
  • 感谢 Ivan Shatsky,我已经更改了 proxy_send_timeout 和 proxy_read_timeout,但没有帮助
  • 仅供参考,有同样的问题,增加读/写超时+正文大小,在我的情况下文件大小不超过100MB

标签: c# asp.net-mvc linux nginx asp.net-core


【解决方案1】:

你有没有试过这个动作:

[RequestSizeLimit(1024*1024*100)]
public IActionResult Post(){
}

或 Program.cs 用于全局设置

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
    {
        options.Limits.MaxRequestBodySize = 1024*1024*100; //100MB
    });
}

或者这个来自中间件

app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), appBuilder =>
{
    context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null;
    //TODO: take next steps
});

【讨论】:

    猜你喜欢
    • 2017-11-26
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    相关资源
    最近更新 更多