I'm writing an nginx configuration that requires a proxy, and I need to original ip address. Nginx's HttpProxyModule's $proxy_add_x_forwarded_for
variable seems perfectly adequate for the task, except that my Nginx is behind a load balance that sets not X-Forwarded-For
, but X-Cluster-Client-Ip
.
Now, one possibility would be using
set X-Forwarded-For $http_x_cluster_client_ip,$proxy_add_x_forwarded_for
but sometimes there are direct accesses to the server, which would leave a leading comma in the header. I thought about using if
, but that scenario falls right in the middle of the cases where if
is problematic to use.
Note that, because the client might have been proxied, I do want to preserve any data present in the X-Forwarded-For
header, if one exists, in addition to passing data from X-Cluster-Client-Ip
.
Any alternatives?
You can use the nginx HttpRealipModule to filter accesses from the Loadbalancer instead:
http://wiki.nginx.org/HttpRealipModule