From 8bb2df597a21a5d9a7e4faf4c81b137b5456c96b Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 25 Nov 2020 12:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AHttpContextutils.get?= =?UTF-8?q?RequestServerNameAndPort()=E6=94=AF=E6=8C=81=E4=BB=8Enginx?= =?UTF-8?q?=E8=8E=B7=E5=8F=96X-Forwarded-Scheme=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/commons/tools/utils/HttpContextUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpContextUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpContextUtils.java index 3a46b806c5..6c3f50f057 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpContextUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpContextUtils.java @@ -69,6 +69,11 @@ public class HttpContextUtils { public static String getRequestServerNameAndPort() { HttpServletRequest request = getHttpServletRequest(); - return String.format("%s://%s:%s", request.getScheme(), request.getServerName(), request.getServerPort()); + //X-Forwarded-Scheme是nginx中添加的一个header,用于获取真实的$scheme + String scheme = request.getHeader("X-Forwarded-Scheme"); + if (StringUtils.isBlank(scheme)) { + scheme = "http"; + } + return String.format("%s://%s:%s", scheme, request.getServerName(), request.getServerPort()); } }