diff --git a/QRCodeService/Startup.cs b/QRCodeService/Startup.cs index ecc6f47..03e8c55 100644 --- a/QRCodeService/Startup.cs +++ b/QRCodeService/Startup.cs @@ -7,6 +7,7 @@ using Infrastructure.Repositories; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Redis; @@ -78,6 +79,12 @@ namespace QRCodeService //redis cache services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value); + //反向代理中间件 + services.Configure(options => + { + options.ForwardedHeaders = + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + }); } // 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.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1")); } + app.UseForwardedHeaders(); app.UseRouting();