How does the lnmp environment under Docker get clientIp and host Ip?

  docker, question

First of all, I use docker under Mac and use a container in docker to install lnmp environment. When the user accesses, when the project obtains the visitor Ip, it will always be a docker bridged ip such as, and the client ip will not be available. Google took a long time to solve it. solve
At the same time, I also want to go to the ip of the host. Thank you

The following is the NGINX configuration

listen 80;
 server_name www.nihao.test;
 location / {
 proxy_pass http://www.nihao.test;
 proxy_set_header    Host             $host:$server_port;  # Don't forget the port after forwarding
 proxy_set_header    X-Real-IP        $remote_addr;
 proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
 proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;  # Key Sentences
 proxy_set_header    X-Forwarded-Proto $scheme;
 proxy_redirect      default;
 try_files $uri $uri/ $uri=404;

I have also encountered this problem. It seems that it is not possible to directly configure Nginx. The problem seems to exist from 2015 to 2018.

Relevant problems found through search

Document how to get real remote client ip for service running in container

Nginx get client IP implementationAccording to configured but unable to get real IP

Network _ mode-doc network connection method

nginx cannot get to client IP

= = = = = = update 15: 17: 52 on September 15, 2018 = = = = =

MAC- Only the IP of the container can be obtained. However, the real IP of the client can be obtained on Linux.Information about the problem