What is the difference between X-Forwarded-For and X-Real-IP?
After testing, I found that the IP obtained is the same.
小伙看你根骨奇佳,潛力無(wú)限,來(lái)學(xué)PHP伐。
Generally speaking, X-Forwarded-For
是用于記錄代理信息的,每經(jīng)過(guò)一級(jí)代理(匿名代理除外),代理服務(wù)器都會(huì)把這次請(qǐng)求的來(lái)源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
發(fā)出,經(jīng)過(guò)三層代理,第一層是2.2.2.2
,第二層是3.3.3.3
,而本次請(qǐng)求的來(lái)源IP4.4.4.4
is the third layer proxy
AndX-Real-IP
,沒(méi)有相關(guān)標(biāo)準(zhǔn),上面的例子,如果配置了X-Read-IP
, there may be two situations
// 最后一跳是正向代理,可能會(huì)保留真實(shí)客戶端IP
X-Real-IP: 1.1.1.1
// 最后一跳是反向代理,比如Nginx,一般會(huì)是與之直接連接的客戶端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