更改 MaxRequestBodySize 到配置文件。
This commit is contained in:
parent
d53bf636bb
commit
86e3c07d0b
@ -5,12 +5,15 @@
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
@ -29,7 +32,6 @@ public class Program
|
||||
try
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
@ -70,10 +72,6 @@ public class Program
|
||||
// // 启用流式传输(不缓冲整个请求体)
|
||||
// serverOptions.AllowSynchronousIO = true;
|
||||
//});
|
||||
webHostBuilder.ConfigureKestrel(options =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = 1024 * 1024 * 1024; // 1024MB //设置最大请求体大小为1G
|
||||
});
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<ProjectGuid>def2e322-9075-4c3f-9967-7eaf0ee28ceb</ProjectGuid>
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
@ -4,24 +4,26 @@
|
||||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using FastTunnel.Api.Filters;
|
||||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using FastTunnel.Core.Config;
|
||||
using System.Text;
|
||||
using FastTunnel.Api.Filters;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Serilog;
|
||||
|
||||
|
||||
#if DEBUG
|
||||
using Microsoft.OpenApi.Models;
|
||||
//using Microsoft.OpenApi.Models;
|
||||
#endif
|
||||
|
||||
namespace FastTunnel.Server;
|
||||
@ -51,6 +53,27 @@ public class Startup
|
||||
// options.BufferBody = false; // 关键:避免缓冲导致的中断
|
||||
//});
|
||||
|
||||
|
||||
long maxSize = Configuration.GetValue<long>("Kestrel:Limits:MaxRequestBodySize");
|
||||
Log.Information("Kestrel:Limits:MaxRequestBodySize:" + maxSize);
|
||||
// 配置Kestrel服务器的MaxRequestBodySize
|
||||
services.Configure<KestrelServerOptions>(options =>
|
||||
{
|
||||
// 设置为1GB(字节),设为null表示无限制(不推荐生产环境)
|
||||
options.Limits.MaxRequestBodySize = maxSize;
|
||||
// 可选:同时配置其他Kestrel限制
|
||||
//options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10);
|
||||
//options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(5);
|
||||
Log.Information($"Kestrel MaxRequestBodySize set to: {options.Limits.MaxRequestBodySize} B");// 1024MB
|
||||
});
|
||||
|
||||
// 若使用IIS集成模式,还需配置IISServerOptions(可选)
|
||||
services.Configure<IISServerOptions>(options =>
|
||||
{
|
||||
options.MaxRequestBodySize = maxSize; // 对IIS生效
|
||||
Log.Information($"IIS MaxRequestBodySize set to: {options.MaxRequestBodySize} B");// 1024MB
|
||||
});
|
||||
|
||||
services.AddAuthorization();
|
||||
|
||||
services.AddControllers();
|
||||
@ -58,7 +81,7 @@ public class Startup
|
||||
#if DEBUG
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v2", new OpenApiInfo { Title = "FastTunel.Api", Version = "v2" });
|
||||
//c.SwaggerDoc("v2", new OpenApiInfo { Title = "FastTunel.Api", Version = "v2" });
|
||||
});
|
||||
#endif
|
||||
// -------------------FastTunnel STEP1 OF 3------------------
|
||||
|
||||
@ -3,5 +3,10 @@
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
},
|
||||
"Kestrel": {
|
||||
"Limits": {
|
||||
"MaxRequestBodySize": 1048576000 // 设置为1000MB(单位:字节),可根据需求调整
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user