X-Forwarded-For X-Forwarded-For is an extension header. The HTTP/1.1 (RFC 2616) protocol does not define it, it was originally introduced by Squid, a caching proxy software, to represent the real IP of the HTTP requester, and has now become a de facto standard, widely used by major HTTP proxies, load balancing and other forwarding services, and written into the RFC 7239 (Forwarded HTTP Extension) standard.
In a network structure with multiple layers of proxies (e.g., a CDN and Anti-DDoS Pro IP address connected to a web application firewall), the IP addresses of all proxies are added to the x-forwarded-for field. This is because the proxy server writes the proxy IP address for each forwarding.
The format is as follows:
X-Forwarded-For: client_ip, proxy1_ip, proxy2_ip Forge X-Forwarded-For
We add the X-Forwarded-For request header via postman, which forges something like this:
I used Alibaba Cloud's SLB service, SLB -> IIS, if we get the first IP address, it must be incorrect, the last IP address is the real IP address of the client.
(In real life, you need to obtain it according to your own architecture, and obtaining the real IP address of the client depends on how many layers of proxies you have gone through.You believe in the first layer)
For using nginx as a reverse proxy, you can set it up as follows:
The outermost proxy server does not trust the X-Forwarded-For input of the client, directly overwriting it, rather than appending it.
|