喷涂clientIP给出错误的地址

时间:2016-12-18 21:41:13

标签: amazon-web-services elastic-beanstalk spray clientip

我在ElasticBeanstalk上运行的docker镜像中akka-spray后面有一个nginx服务器。我试图用这个来获取客户端IP:

  (path("myip") & get) {
      clientIP {     
        ip => complete("Client's ip is " + ip.toOption.map(_.getHostAddress).getOrElse("unknown"))  
      }
  } ~

我的配置也有 remote-address-header = on

我的ngingx.conf

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    server {

        listen 80;

        location / {
            proxy_pass http://127.0.0.1:8080/;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}

将我的浏览器指向/myip端点会给我错误的IP地址。它给出了172.something,我假设它是负载均衡器。它当然不是我的浏览器。我应该使用.getHostAddress以外的其他内容吗?使用原始ip会产生相同的错误值。感谢。

0 个答案:

没有答案