L79

Nginx geo模块-LMLPHP

Nginx geo模块-LMLPHP

Nginx geo模块-LMLPHP

geo 模块默认编译进nginx 可以通过--without-http_geo_module禁用

Syntax:geo [$address$variable { ... }
Default:
Context:http
  1. 1:如果geo指令后不输入$address 那么默认就使用变量$remite_addr作为ip地址
  2. 2:{} 内的指令匹配:优先最长匹配
geo $country {
default ZZ;
proxy 116.196.115.53;
127.0.0.0/ US;
127.0.0.1/ RU;
10.1.0.0/ RU;
192.168.1.0/ UK;
} server {
listen ;
server_name shop.com.cn location /{ return '$country\n';
}
}

然后测试该配置 curl -H 'X-Forwarded-For:192.168.1.123' https://shop.com.cn/

返回 UK 字符串 因为匹配到了 192.168.1.123

05-11 18:11