Is there a way to pass the correct remote address to Nginx in a Docker container

Viewed 127

I have a Nginx webserver that I'm running from inside a docker container. The problem I am having is that all client IP addresses in the nginx access.log are 172.19.0.1, the container's gateway. I would like the IP addresses shown to nginx to be the real IP addresses of the clients.

I've tried a few solutions that I found, including

  1. Using Nginx's realip module
    set_real_ip_from 172.19.0.1;
    real_ip_header X-Real-IP;
    real_ip_recursive on;

which still logged the gateway ip

  1. Setting the ports to host networking mode, which was ineffectual because I'm on macOS, and it is only supported on Linux.

The dockerfile I'm using looks like this

version: "3"
services:
    nginx:
        container_name: nginx
        ports:
            - target: 80
              published: 80
            - target: 443
              published: 443
        volumes:
            # [my volumes]
        restart: unless-stopped
        image: nginx
0 Answers
Related