首页
App
&
Coffee
文档
项目
分享
反馈
俱乐部
登录
注册
IpKit.getRealIp有时候可以获得到真实ip,有时候不能,前端NGINX
陈伟
2018-01-05 19:29
都是调用的同一个方法,为什么会有两种不同的结果?
项目:
JFinal
评论区
杜福忠
2018-01-05 23:47
把NGINX的配置贴出来看看,有
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
吗?
看看kit工具里面写的:
/**
* IpKit 获取 ip 地址的工具类
*/
public class IpKit {
public static String getRealIp(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
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();
}
return ip;
}
所以NGINX得带着传过来的才有的
回复
发送
我要反馈
热门反馈
扫码入社
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
吗?
看看kit工具里面写的:
/**
* IpKit 获取 ip 地址的工具类
*/
public class IpKit {
public static String getRealIp(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
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();
}
return ip;
}
所以NGINX得带着传过来的才有的