zoukankan      html  css  js  c++  java
  • 获取nginx代理情况下的真实ip

    location  /xxx/ {
        proxy_pass http://192.168.4.5:8080/xxx/;
        proxy_set_header  Host             $host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
    public String getRemoteIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        logger.info("===========x-forwarded-for======="+ip);//这一步一般能获取到
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
            logger.info("===========Proxy-Client-IP======="+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();
        }
        final String[] arr = ip.split(",");for (final String str : arr) {
            if (!"unknown".equalsIgnoreCase(str)) {
                ip = str;
                break;
            }
        }
        return ip;
    }
  • 相关阅读:
    golang-uuid
    golang-random随机数
    git status检测不到文件变化
    vimium
    go1.11新特性,mark一下
    HTML网页滚动加载--mark一下
    docker-清理none镜像等操作
    golang websocket
    postman 快捷方式--启动图标
    tmux基本操作
  • 原文地址:https://www.cnblogs.com/xiaoliu66007/p/13966140.html
Copyright © 2011-2022 走看看