Show Real IP Nginx Behind Reverse Proxy

When your Nginx web server is running behind a reverse proxy, you will see IP of the reverse proxy server as visitor IP in web servers access log.

To fix this, edit nginx.conf file

vi /etc/nginx/nginx.conf

Find

http {

Inside http section, add

set_real_ip_from IP_ADDRESS_OF_PROXY_SERVER_HERE;
real_ip_header X-Forwarded-For;

Example

set_real_ip_from 192.168.122.1;
real_ip_header X-Forwarded-For;

Restart Nginx

nginx -s reload
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *