Symfony2 - How to get real server ip address?

2019-09-11 19:20发布

问题:

I am currently using:

$this->request->server->get('SERVER_ADDR');

When the application is deployed to the real server, the value returned is 127.0.0.1, which is not correct. It should be the real ip address.


There seem to be a proxy there, since we had problems with getting the client ip address with:

$this->request->server->get('REMOTE_ADDR');

I have fixed that I get client ip address using:

$this->request->getClientIp();

Maybe to get the real server ip address, there is also another more reliable way?