3

In my VPS I am hosting several websites. everyone living in its own Linux Container. For instance

Site #1 -> 10.0.3.111

Site #2 -> 10.0.3.112

Site #3 -> 10.0.3.113

To know where to redirect each request, I also have a reverse proxy nginx in another Linux Container in 10.0.3.101

The problem I am having is that in one of my websites, which is running Laravel, I try to get the IP of the client, like this:

<p>IP Address: {{ Request::getClientIp() }}</p>

The problem is that I am getting all the time 10.0.3.101, instead of the IP of the client.

I guess Laravel is getting the IP of the last host where the request came thought, not the initial one that started the request.

Is there a way that I could get that IP, without changing this structure?

Configurations

This is my nginx hostfile:

server {
        listen 80;
        server_name example.com www.example.com;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass http://10.0.3.115;
        }
}
Enrique Moreno Tent
  • 429
  • 2
  • 7
  • 19

1 Answers1

2

You need to set trusted proxy. In that case getClientIp() will use X-Forwarder-For header to get client IP address.

Alexey Ten
  • 7,922
  • 31
  • 35