Nginx Docker Swarm : get real IP in logs

Viewed 192

I have a docker swarm cluster. I use nginx as a reverse proxy.

Here is the configuration :

worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    # Do not show nginx version
    server_tokens off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    server {
        listen 8080;

        client_max_body_size 11M;

        location / {
            proxy_pass http://my_service:8000;
            proxy_set_header Host $host;
        }
    }
}

I also tried to add this :

log_format main '$remote_addr forwarded for $http_x_real_ip - $remote_user [$time_local]  '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent"';

But the result is the same :

10.0.0.4 - - [06/Mar/2022:11:54:20 +0000] "POST /api/v1/applications HTTP/1.1" 200 45 "-" "Java/1.8.0_191"

The IP is still 10.0.0.4 and I don't know where it comes from.

0 Answers
Related