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

$request->getClientIp()

  • How can I tell in Dockerfile which comand I want to execute when input “docker run” command?
  • Dockerhub Automated Builds tagging
  • Docker can create a new swarm
  • Limitations in Mesos and Marathon Regarding Docker
  • Synchronizing multiple servers and local machines with the same data / source code
  • Expressjs app started with PM2 in Docker dies with SIGINT
  • 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:

    192.168.80.2
    218.205.17.167
    192.168.80.2
    

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

    XX.XXX.236.29
    
    XX.XXX.236.29
    

    The configuration of nginx:

    server { 
        listen       80; 
        server_name  myserver.com; 
    
        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!

  • Kubernetes: creating pod with specific environments
  • In virtual-machine Docker push to private registry failed under proxy
  • Is it safe to use same host volume in multiple containers?
  • Can I use docker to provide a simple file overlay over my current system?
  • Docker container cannot resolve hosts
  • Cant connect to docker mongodb
  • 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.