3
3
3epo2021-10-30 11:39:52
Nginx
3epo, 2021-10-30 11:39:52

How to make the correct display of the visitor's ip in the nginx logs with a proxy?

Help me figure out the correct display of the real ip address of the visitor to the site.
There is a server on which the site is running, but nginx is configured to proxy requests to the local ip to the site.
At the same time, the logs show that the user came from the nginx ip address. How to make me see the real ip of the visitor's site in the nginx logs.

Here is the nginx config:

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

server {
    listen 127.0.0.1:8443 ssl http2;
    server_name example.com www.example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/example.com/privkey.pem;
    include /etc/nginx/snippets/ssl-params.conf;
    client_max_body_size 0;

  location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        set_real_ip_from 127.0.0.1; 
        real_ip_header X-Forwarded-For;
        proxy_pass http://127.0.0.1:1024;
        access_log /var/log/nginx/access123.log custom;
}
}

But with these settings in the logs shows:
127.0.0.1 forwarded for - - - [30/Oct/2021****

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-10-30
@ky0

https://nginx.org/ru/docs/http/ngx_http_realip_mod...
If it doesn't work, it means that something was not taken into account or configured incorrectly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question