Greetings!
Have problem while getting user real IP - it always shows as container ip.
Im using docker 1.12 in swarm mode, 3 services with 2 replicas each.
2 gateway service replicas - whic dontains nginx and forward requests based on host
2 app1 service replicas - lets call it app1.example.com
2 app2 service replicas - app2.example.com
Thats how i created these services
docker service create --name gateway --replicas=2 -p 80:80 -p 443:443 --network ingress my.registry.com:5000/general/gateway
docker service create --name app1 --replicas=2 --network ingress my.registry.com:5000/general/app1
docker service create --name app2 --replicas=2 --network ingress my.registry.com:5000/general/app2
Ingress network:
docker network create --driver overlay ingress
Gateway nginx config looks something like this:
server {
listen 80;
server_name app1.example.com;
proxy_redirect off;
proxy_set_header Host $host;
location / {
set $target app1;
proxy_pass http://$target;
}
}
server {
listen 80;
server_name app1.example.com;
proxy_redirect off;
proxy_set_header Host $host;
location / {
set $target app2;
proxy_pass http://$target;
}
}
So based on requested host i redirect to appropriate docker service.
Problem is - in nginx logs and in php application client IP shows as gateway container IPs e.g. 10.255.0.7
Any ideas how can I restore original client ip if i use docker loadbalancing?
Docker version 1.12.1, build 23cf638