0
0
0xc00000e92020-01-01 20:28:57
PHP
0xc00000e9, 2020-01-01 20:28:57

How to pass real IP to Laravel?

There is a project on Laravel, under docker (php-fpm 7.4, nginx stable alpine). I'm trying to get the client's IP in the request, but I end up getting the docker's IP. I just tried everything: nginx'a, docker-compos'a configs - all to no avail. The IP of the company is white, the ports are open.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danila534, 2020-01-01
@Danila534

$ipaddress = '';
        if (isset($_SERVER['HTTP_CLIENT_IP']))
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
        else if (isset($_SERVER['HTTP_X_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
        else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
        else if (isset($_SERVER['HTTP_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_FORWARDED'];
        else if (isset($_SERVER['REMOTE_ADDR']))
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        else
            $ipaddress = 'UNKNOWN';

Further...
return $ipaddress;

K
ky0, 2020-01-02
@ky0

To forward the client's real address in nginx, there is a corresponding module .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question