添加反向代理中间件配置

This commit is contained in:
2021-02-25 16:00:07 +08:00
parent dfbc8f737d
commit 67dc2d5b4e

View File

@@ -7,6 +7,7 @@ using Infrastructure.Repositories;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Caching.Redis;
@@ -78,6 +79,12 @@ namespace QRCodeService
//redis cache //redis cache
services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value); services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value);
//反向代理中间件
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -89,6 +96,7 @@ namespace QRCodeService
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1")); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1"));
} }
app.UseForwardedHeaders();
app.UseRouting(); app.UseRouting();