通过nginx中转获取不到IP的问题解决

第一步:在nginx.conf中配置反向代理时把真实IP带上,例如:

server {

listen 80;

server_name myibook.com.cn;

location ~ ^/(WEB-INF)/ {

deny all;

}

location / {

proxy_pass http://localhost:8888;

proxy_set_header x-client-ip $remote_addr;

}

}

第二步:应用程序中用 String ip = request.getHeader("x-client-ip");替代String ip = request.getRemoteAddr();即可