ai-fix: https forward
This commit is contained in:
parent
f519405c63
commit
e315e03922
@ -9,6 +9,7 @@ using Fake.Serilog;
|
|||||||
using FluentValidation.AspNetCore;
|
using FluentValidation.AspNetCore;
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
using OpenTelemetry.Resources;
|
using OpenTelemetry.Resources;
|
||||||
@ -134,12 +135,26 @@ public class TrackCenterApiModule : FakeModule
|
|||||||
|
|
||||||
// 添加授权服务
|
// 添加授权服务
|
||||||
services.AddAuthorization();
|
services.AddAuthorization();
|
||||||
|
|
||||||
|
services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
// 反向代理场景下恢复客户端真实来源信息,供 Swagger、鉴权和重定向等中间件使用
|
||||||
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor |
|
||||||
|
ForwardedHeaders.XForwardedProto |
|
||||||
|
ForwardedHeaders.XForwardedHost;
|
||||||
|
options.KnownNetworks.Clear();
|
||||||
|
options.KnownProxies.Clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ConfigureApplication(ApplicationConfigureContext context)
|
public override void ConfigureApplication(ApplicationConfigureContext context)
|
||||||
{
|
{
|
||||||
var app = context.GetWebApplication();
|
var app = context.GetWebApplication();
|
||||||
var configuration = context.GetConfiguration();
|
var configuration = context.GetConfiguration();
|
||||||
|
|
||||||
|
// 必须在读取 Scheme/Host/PathBase 的中间件之前执行,否则 Swagger 会生成错误的请求地址
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
app.Use(async (httpContext, next) =>
|
app.Use(async (httpContext, next) =>
|
||||||
{
|
{
|
||||||
httpContext.Request.EnableBuffering();
|
httpContext.Request.EnableBuffering();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user