spring mvc 獲取nginx下用(use)戶真實ip
如果經過多台服務器Nginx轉發,獲取的(of)ip内容類似這(this)樣218.5.70.170, 192.168.1.1,所以(by)過濾掉空格取第1個(indivual)就是(yes)。
private String getRemortIP(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
ip = ip.replace(" ", "").trim();
if (StringUtils.isNotBlank(ip)) {
String[] ips = ip.split(",");
ip = ips[0];
}
logService.log(request.getRequestURL().toString(), request.getMethod(), ip, 0);
return ip;
}
- 版權所有:奇站網絡 轉載請注明出(out)處
- 廈門極極網絡科技有限公司,專業提供網站建設,響應式網站建設,小程序開發,系統定制開發。
- 軟件開發咨詢熱線:吳小姐 13313868605