Blog entries tagged with 'apache'

  • Getting the client IP address behind a proxy in Apache

    By Nuno Mariz, on 20 May 2009 @ 09:45

    Typically in my Django projects deployments I use Nginx as a front-end web server to handle static content while proxying all other requests to Apache.

    When the request arrives to Apache, the client IP address is 127.0.0.1. We need to configure Apache to accept the IP address from X-Real-IP or X-Forwarded-For headers set by Nginx.

    To solve this problem I use mod_rpaf that does exactly the opposite of mod_proxy_add_forward.

    In my Nginx virtualhost configuration I have something like:

    server {
        ...
        location  / {
            proxy_pass        http://127.0.0.1:8080;
            proxy_set_header  Host             $http_host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
            ...
        }
        ...
    }
    

    This also applies if your are using a different webserver as front-end such as Lighttpd or another instance of Apache.

Tags related