From 22a9110af912626659e88df1ae9a878b465596ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sun, 19 Jun 2022 00:18:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E8=A7=A3?= =?UTF-8?q?=E5=86=B3Ubuntu=20Nginx=20=E4=BB=A3=E7=90=86=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9C=9F=E5=AE=9EIP=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Web.Admin/Startup.cs | 8 ++++++++ CoreCms.Net.Web.WebApi/Startup.cs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/CoreCms.Net.Web.Admin/Startup.cs b/CoreCms.Net.Web.Admin/Startup.cs index 3052590..18d2028 100644 --- a/CoreCms.Net.Web.Admin/Startup.cs +++ b/CoreCms.Net.Web.Admin/Startup.cs @@ -15,6 +15,7 @@ using Essensoft.Paylink.Alipay; using Essensoft.Paylink.WeChatPay; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; @@ -171,6 +172,13 @@ namespace CoreCms.Net.Web.Admin /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + #region 解决Ubuntu Nginx 代理不能获取IP问题 + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); + #endregion + // 记录请求与返回数据 (注意开启权限,不然本地无法写入) app.UseRequestResponseLog(); // 用户访问记录(必须放到外层,不然如果遇到异常,会报错,因为不能返回流)(注意开启权限,不然本地无法写入) diff --git a/CoreCms.Net.Web.WebApi/Startup.cs b/CoreCms.Net.Web.WebApi/Startup.cs index c83893a..3a99fe7 100644 --- a/CoreCms.Net.Web.WebApi/Startup.cs +++ b/CoreCms.Net.Web.WebApi/Startup.cs @@ -34,6 +34,7 @@ using CoreCms.Net.WeChat.Service.Mediator; using Essensoft.Paylink.Alipay; using Essensoft.Paylink.WeChatPay; using MediatR; +using Microsoft.AspNetCore.HttpOverrides; namespace CoreCms.Net.Web.WebApi { @@ -178,6 +179,13 @@ namespace CoreCms.Net.Web.WebApi /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + #region 解决Ubuntu Nginx 代理不能获取IP问题 + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); + #endregion + // 记录请求与返回数据 (注意开启权限,不然本地无法写入) app.UseRequestResponseLog(); // 用户访问记录(必须放到外层,不然如果遇到异常,会报错,因为不能返回流)(注意开启权限,不然本地无法写入) -- Gitee