Get real client IP for Apache server behind Nginx Proxy Server

Step to configuration:

    # Set headers
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    # in lxd container as root user
    apt-get install unzip build-essential apache2-dev

    # download and install mod_rpaf for apache
    wget https://github.com/gnif/mod_rpaf/archive/stable.zip
    # unzip
    unzip stable.zip
    cd mod_rpaf-stable/
    make
    make install

    # create file rpad.load
    nano /etc/apache2/mods-available/rpaf.load
    # add following lines:
    LoadModule rpaf_module /usr/lib/apache2/modules/mod_rpaf.so
    # create file rpaf.conf
    nano /etc/apache2/mods-available/rpaf.conf
    # add following lines:
    # note: your_server_ip = internal_ip of host with lxd container, see diagram
    <IfModule mod_rpaf.c>
            RPAF_Enable             On
            RPAF_Header             X-Real-Ip
            RPAF_ProxyIPs           your_server_ip 
            RPAF_SetHostName        On
            RPAF_SetHTTPS           On
            RPAF_SetPort            On
    </IfModule>

    # enable mod:
    a2enmod rpaf

    # test config is ok
    apachectl -t

    # restart apache
    apachectl -t

Origin post at https://archive.camratus.com/2017/10/06/get-real-client-ip-for-apache-server-behind-nginx-proxy-server/ (2017-10-06)

Tags:
#nginx #ubuntu #apache #proxy