Nginx proxy pass real ip doesn't work

I run a nginx reverse proxy server in the docker container. And the backend is a apache server running on the host, which is listening 10082 port. Laravel handle the request. And I use


  • PhpStorm xdebug can't find file when connection comes from docker container
  • Explanation of this docker file?
  • Execute mongodb binaries on alpine linux
  • Docker-compose error when try to start
  • Docker mine craft connection issues
  • Docker: how to force graylog web interface over https?
  • to get real ip. However, the result of visiting the server by http://myip:10082 directly without proxy conflicts with the result of visiting it by reverse proxy.

    The test code in laravel:

    echo $request->ip().'<br>';
    echo $request->headers->get('X-Real-IP').'<br>';
    echo $request->getClientIp().'<br>';

    The result with proxy:

    The result without proxy(the XX.XXX.236.29 is my real ip):


    The configuration of nginx:

    server { 
        listen       80; 
        access_log  logs/myserver.access.log  main;
        location / { 
            proxy_pass http://myip:10082;
            proxy_set_header   Host    $host; 
            proxy_set_header   X-Real-IP   $remote_addr; 
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 

    I’m so confused. Could someone help me solve it. Thanks!

  • Using a buildroot distro as a docker *host*
  • Docker container run error: Container exited on error: exited with status 1
  • Container does not start if I map existing in container dir
  • Docker on Azure .Net Core WebApi with continuous deployment - did it work?
  • Deploying Meteor application with Docker and phusion-passenger
  • docker can't connect to boot2docker because of tcp timeout
  • One Solution collect form web for “Nginx proxy pass real ip doesn't work”

    Since you have set the X-Real-IP header in your nginx proxy, it’s the real ip.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.