通过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();即可 

posted @ 2017-10-15 15:57  netcorner  阅读(1434)  评论(0编辑  收藏  举报