0

I configured apache-2.4 on windows as a reverse-proxy for my internal nginx server on linux (I know! But don't ask me why!!). Almost everything works great, except:

I believe I have configured nginx to log the real ip using this header: X-Real-IP. Reference. Now in my reverse-proxy what do I do to set this header to the IP address of the client so that it can be logged. Note that SSL is a must on apache-2.4. Currently my http-vhosts.conf has this:

<VirtualHost _default_:443>
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Ssl on
    RequestHeader set X-URL-SCHEME https
    ServerName www.external.gateway:443
    ServerAlias external.gateway:443 
    ErrorLog "C:/Apache24/logs/gateway-error.log" 
    CustomLog "C:/Apache24/logs/gateway-access.log" common
    # ServerAdmin admin@gateway.com

    SSLEngine On
    SSLCertificateFile C:/Apache24/ssl/external.gateway.crt
    SSLCertificateKeyFile C:/Apache24/ssl/external.gateway.key
    <Location />
       SSLRequireSSL
    </Location>

    ProxyPreserveHost On
    ProxyPass / http://internal.nginx:80/
    ProxyPassReverse / http://internal.nginx:80/
</VirtualHost>

PS: I can probably use X-Forwarded-For in nginx, but I need to know what to do to set that header in apache httpd.conf. Any help is appreciated.

  • If you're using mod_proxy_http then that is already adding X-Forwarded-For headers to requests to the backend server. See httpd.apache.org/docs/2.4/mod/mod_proxy.html#x-headers – wurtel Mar 15 '17 at 19:44
  • Thanks for the feedback, I will try as you suggested and post an update when I get a chance. – code4kix Mar 16 '17 at 15:19
  • @wurtel, I just had to enable mod_proxy_http, configure nginx to use that header... and viola, it works like a charm! If you post an answer I will accept it or I will wait a little and post an answer myself for the benefit of others. – code4kix Mar 17 '17 at 19:15
1

Credit to wurtel

  • Enable mod_proxy_http in apache httpd (reverse-proxy) in the httpd.conf, like so:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so

  • Use X-Forwarded-For to log the IP in nginx (upstream) as mentioned here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.