优化:使用nginx代理时,会获取到多个ip,取第一个真实ip

This commit is contained in:
刘志平 2021-04-16 16:53:50 +08:00
parent 2b7ac9ab98
commit 059d976718
1 changed files with 3 additions and 1 deletions

View File

@ -40,7 +40,9 @@ public class IpUtils
ip = request.getRemoteAddr();
}
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
//使用nginx代理时会获取到多个ip取第一个真实ip
return ip.split(",").length>1?ip.split(",")[0]:ip;
}
public static boolean internalIp(String ip)