Commit c2674051 by 李传峰

feat:[none] 增加X-Real-IP方法

parent 13130d9c
......@@ -20,6 +20,19 @@ import org.apache.commons.lang.StringUtils;
public class NginxUtils {
/**
* 优先获取X-Real-IP
* @param request Request
* @return IP
*/
public static String getXRealIp(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (StringUtils.isNotBlank(ip) && !"unKnown".equalsIgnoreCase(ip)) {
return ip;
}
return getClientIp(request);
}
/**
* 在很多应用下都可能有需要将用户的真实IP记录下来,这时就要获得用户的真实IP地址,在JSP里,获取客户端的IP地
* 址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的。但是在通过了Apache,Squid等
* 反向代理软件就不能获取到客户端的真实IP地址了。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment