在Nginx.conf中:
http {
geoip_country /etc/Nginx/GeoIP.dat;
...
}
如果我做:
server{
...
location / {
add_header X-Geo $geoip_country_code;
add_header X-Geo3 $geoip_country_code3;
add_header X-IP $remote_addr;
...
}
}
$curl -I www.example.org
HTTP/1.1 302 FOUND
Content-Type: text/html; charset=utf-8
Date: Thu,17 Jan 2013 19:29:23 GMT
Location: http://www.example.org/login/?next=/
Server: Nginx/1.2.2
Vary: Cookie
X-IP: 10.139.34.12
Connection: keep-alive
如果我将位置块更改为:
location / {
add_header X-Geo "foo";
add_header X-Geo3 "bar";
add_header X-IP $remote_addr;
...
}
最佳答案
我刚刚发现geo_ip有一个内部选项来使用X-Forwarded-For:
原文链接:https://www.f2er.com/nginx/435107.htmlSyntax: geoip_proxy address | CIDR;
default: —
context: http
This directive appeared in versions 1.3.0 and 1.2.1.
Defines trusted addresses. When a request comes from a trusted address,an address from the “X-Forwarded-For” request header field will be used instead.