K
K
kiloper2014-12-22 21:40:53
Nginx
kiloper, 2014-12-22 21:40:53

How to get real IP address in nginx logs?

Good day, I have a trace. situation. There is a proxy nginx (with two interfaces: external IP and internal - 192.168.1.1), inside the network at the address 192.168.1.6, the nginx (backend) server also accepts requests. Everything works, but on the backend in the nginx logs I see the internal IP of the proxy server 192.168.1.1 And you need to see the client's IP I am attaching
the setting
server {
server_name ххххххх;
location / {
proxy_redirect off;
proxy_pass http://192.168.1.6;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
J_o_k_e_R, 2014-12-22
@kiloper

Use the http_realip_module module on the backend .
Example:
set_real_ip_from 192.168.1.0/24;
set_real_ip_from 192.168.2.1;
set_real_ip_from 2001:0db8::/32;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question