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 [email protected] 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.

3
  • 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 Commented Mar 15, 2017 at 19:44
  • Thanks for the feedback, I will try as you suggested and post an update when I get a chance. Commented Mar 16, 2017 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. Commented Mar 17, 2017 at 19:15

1 Answer 1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.