我在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
会产生相同的错误值。感谢。