I have an akka-spray
server behind nginx
in a docker image running on ElasticBeanstalk. I'm trying to get the client IP with this:
(path("myip") & get) {
clientIP {
ip => complete("Client's ip is " + ip.toOption.map(_.getHostAddress).getOrElse("unknown"))
}
} ~
My config also has
remote-address-header = on
My ngingx.conf
is
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;
}
}
}
Pointing my browser at the /myip
endpoint gives me the wrong ip address. It's giving a 172.something, which I assume is the load balancer. It's certainly not my browser. Should I be using something other than .getHostAddress
? Using the raw ip
gives the same, wrong, value. Thanks.