0

I set a server 130.153.32.231 (Nginx) as a reverse_proxy for www.mysite.com (Apache) they both had separate server, The problem was how can I get the user real IP address that access 130.153.32.231 and pass it to www.mysite.com without changing anythings in www.mysite.com, because what I can see all user shows 130.153.32.231 not the real IP.

Already try http_realip_module and proxy_set_header X-Forwarded-For but none of this do the job, any ones know how to fix this..

Caknoris
  • 3
  • 2
  • 5
  • What problems do you get with X-Forwarded-For? It is designed to do what you seem to want to achieve. – theduck Aug 07 '19 at 10:41
  • The site www.mysite.com still catch the user ip as 130.153.32.231, not the user ip instead – Caknoris Aug 07 '19 at 10:49
  • So on ngnix side you are using something like `proxy_set_header X-Forwarded-For $remote_addr` and on the site www.mysite.com you are seeing the 'X-Forwarded-For' header set to 130.153.32.231 rather than the $remote_addr? – theduck Aug 07 '19 at 10:53
  • yes that was happened – Caknoris Aug 07 '19 at 10:58

1 Answers1

1

On the nginx side make sure you are passing through the remote address to the X-Forwarded-For header using something like:

proxy_set_header X-Forwarded-For $remote_addr

Then on the Apache side use mod_remoteip (docs here) to take the IP address from the X-Forwarded-For header:

RemoteIPInternalProxy 130.153.32.231
RemoteIPHeader X-Forwarded-For

You also need to tell Apache to trust the proxy (the RemoteIPInternalProxy does this).

theduck
  • 2,589
  • 13
  • 17
  • 23
  • so this cannot be done if we didn't makes any change on the apache site? because I doesn't have accessed on the www.mysite.com – Caknoris Aug 07 '19 at 11:19
  • I don’t believe so as this information isn’t passed from nginx to Apache - Apache works it out from the IP that it received the data from. You would need to make modifications to the Apache side to change this. – theduck Aug 07 '19 at 11:29
  • Also check if you are running nginx at a docker container inside a docker swarm cluster, if yes, then you will have to follow [this steps](https://stackoverflow.com/questions/49415595/docker-swarm-get-real-ip-client-host-in-nginx/50592485#50592485) – deFreitas Feb 16 '21 at 19:01