What is the difference between X-Forwarded-For and X-Real-IP?
After testing, I found that the IP obtained is the same.
曾经蜡笔没有小新2017-05-16 17:28:04
Generally speaking, X-Forwarded-For
是用于记录代理信息的,每经过一级代理(匿名代理除外),代理服务器都会把这次请求的来源IP
追加在X-Forwarded-For
中
A request from 4.4.4.4
, the header contains such a line
X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3
means that the request is sent by 1.1.1.1
and passes through three layers of proxies. The first layer is 2.2.2.2
and the second layer is 3.3.3.3
, and the source IP of this request1.1.1.1
发出,经过三层代理,第一层是2.2.2.2
,第二层是3.3.3.3
,而本次请求的来源IP4.4.4.4
is the third layer proxy
AndX-Real-IP
,没有相关标准,上面的例子,如果配置了X-Read-IP
, there may be two situations
// 最后一跳是正向代理,可能会保留真实客户端IP
X-Real-IP: 1.1.1.1
// 最后一跳是反向代理,比如Nginx,一般会是与之直接连接的客户端IP
X-Real-IP: 3.3.3.3
So, if there is only one layer of proxy, the values of these two headers are the same