I am trying to get client IP with $request->getClientIp(); and it returns 172.19.0.2, but that is not my public IP.
I stumbled upon this doc to set up trusted proxies so I tried doing like this:
// web/app_dev.php
// ...
$request = Request::createFromGlobals();
// tell Symfony about your reverse proxy
Request::setTrustedProxies(['172.19.0.0/8'], Request::HEADER_X_FORWARDED_ALL);
$response = $kernel->handle($request);
// ...
But that did not fix the issue.
What am I doing wrong?
"Public IP"? As explained in "How can I get client real ip address in PHP?"
That means you would need to rely to your reverse proxy (NGiNX in your case) to populate correctly
HTTP_X_FORWARDED_FOR, which you can try and read:Or use this
GetClientIP()function, which would check for:HTTP_CF_CONNECTING_IPHTTP_X_REAL_IPHTTP_CLIENT_IPHTTP_X_FORWARDED_FORHTTP_X_FORWARDEDHTTP_X_CLUSTER_CLIENT_IPHTTP_FORWARDED_FORHTTP_FORWARDEDREMOTE_ADDRAgain, it depends on what the internet-facing reverse-proxy has set.