Real IP Address For Nginx BEHIND A REVERSE PROXY or HA Proxy

Firstly you need to configure HAProxy to pass the client IP address, which is quite simply done by adding the “forwardfor” and “http-server-close” options to the backend, ensuring that the real client IP reaches the backend web servers via the X-Forwarded-For header. Here is the configuration I’m using for my HTTP backend:

Server HA Proxy :

example IP : 192.168.0.1

Configuration haproxy.conf

add line backend http :

option http-server-close

option forwardfor

OR Add line :

defaults

option httpclose
option forwardfor

REstart HAPROXY


Server Nginx :

Nginx Webserver

You’ll need to configure and compile Nginx with the –with-http_realip_module option.

Cek Module nginx http_realip_module option ..

Nginx -V

Then set the following option in the Nginx configuration:

Configuration nginx.conf

set_real_ip_from 192.168.0.1; # <- IP HAPROXY

set_real_ip_from 192.168.1.1; # <- IP HAPROXY

real_ip_header X-Forwarded-For;

   REstart Nginx

Posted on: March 6, 2019, by :