nginx get the user IP gesture

If there http header has X-Real-IP, its value is used as the IP user
if there is X-Forwarded-For http header, the first value is used as the user IP
Otherwise, use the remote address as user IP
X- Forwarded-For part of RFC 7239, usage: X-Forwarded-For: client , proxy1, proxy2

The X-Real-IP is not a standard, but the industry generally use, nginx official documentation with many examples of the X-Real-IP, usage: X-Real-IP: client

Many languages ​​http server libraries are also taken in that order user IP, or similar, do not look at X-Real-IP, etc.

Standard configuration nginx
load balancing configuration, unique to the user is in contact with the external network server, the request is generally used to shunt

location /lb {
proxy_pass http://localhost:8000;
proxy_set_header Host host; # is the original value proxy_host, if it is load balancing, then it should use Host
proxy_set_header X-Real-IP $ REMOTE_ADDR;
}
network location after but can not be set X-Real-IP, and before or you'll server transmission X-Real-IP overwritten

Guess you like

Origin blog.csdn.net/qq_42409788/article/details/81739556