zeldor.biz

Linux, programming and more

Copyright © 2025
Log in

Nginx + apache2 = real-ip

January 30, 2011 by Igor Drobot 4 Comments

Nginx and Apache2 are running great but there is only one tiny problem with the visitors ip’s.

Normaly I let my nginx instance do the logging job, but if you let your Apache do it you will get some problems. Apache will see all incoming requests as coming from localhost (127.0.0.1). Right they are all from nginx.

Solution:

1
2
3
4
5
6
# Install rpaf module for Apache2
aptitude install libapache2-mod-rpaf
# Enable it
a2enmod rpaf
# Restart apache2
/etc/init.d/apache2 restart

# Install rpaf module for Apache2 aptitude install libapache2-mod-rpaf # Enable it a2enmod rpaf # Restart apache2 /etc/init.d/apache2 restart

This tells Nginx to forward the original remote IP-address in the header as it proxys ro Apache.
Add this 3 Lines to your nginx.conf or to your enables site config:

1
2
3
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Filed Under: Debian, HTTP, Linux, Networking Tagged With: apache2, Nginx, Proxy, real-ip, rpaf

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY DNS Fedora FTP Fun Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID rsync Samba security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Comments

  1. Jan Vladimir Mostert says

    January 6, 2014 at 19:37

    Works for me, thanks for the simple solution!!

  2. zeldor says

    May 11, 2011 at 10:02

    I hope it worked fine for you;)

  3. bzion says

    May 11, 2011 at 09:49

    Impeccable. Merci :)

Trackbacks

  1. Forward Connections from Nginx to httpd in CentOS says:
    February 10, 2013 at 14:55

    […] The approach differs slightly from other distributions like Debian. You can find a tutorial for Debian here: http://zeldor.biz/2011/01/nginx-apache2-real-ip/ […]

Leave a Reply

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

Yeaaah Cookie! We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok