I have a webapp under NGinx and another frontal load balancer, something like below (x.x.x.x = IP address):
Client(a.a.a.a) -> LB (b.b.b.b) -> NGX (c.c.c.c) -> WEBAPP (d.d.d.d)
Here is a snippet of my NGinx configuration:
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
real_ip_header X-Forwarded-For;
set_real_ip_from b.b.b.b;
real_ip_recursive on;
}
- The load balancer add
X-Forwarded-For
field with client IP
X-Forwarded-For
=a.a.a.a
- NGinx search for client real IP in
X-Forwarded-For
header by omiting LB IP (b.b.b.b
) and change$remote_addr
fromb.b.b.b
toa.a.a.a
soproxy_set_header X-Real-IP $remote_addr
become true (OK that's what I want !)
BUT, NGinx also completeX-Forwarded-For
header witha.a.a.a
IP instead ofb.b.b.b
- WEBAPP receive the following headers:
X-Forwarded-For
=a.a.a.a, a.a.a.a
X-Real-IP
=a.a.a.a
->X-Forwarded-For
should bea.a.a.a, b.b.b.b
What I need is the ability to set first proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
and then search for real IP and replace $remote_addr
value.
Any one can help me to solve this problem ?