Nginx geoip模块实现地区性负载均衡

2019-10-17 21:20:25刘景俊

CN,02,"Zhejiang"
CN,03,"Jiangxi"
CN,04,"Jiangsu"
CN,05,"Jilin"
CN,06,"Qinghai"
CN,07,"Fujian"
CN,08,"Heilongjiang"
CN,09,"Henan"
CN,10,"Hebei"
CN,11,"Hunan"
CN,12,"Hubei"
CN,13,"Xinjiang"
CN,14,"Xizang"
CN,15,"Gansu"
CN,16,"Guangxi"
CN,18,"Guizhou"
CN,19,"Liaoning"
CN,20,"Nei Mongol"
CN,21,"Ningxia"
CN,22,"Beijing"
CN,23,"Shanghai"
CN,24,"Shanxi"
CN,25,"Shandong"
CN,26,"Shaanxi"
CN,28,"Tianjin"
CN,29,"Yunnan"
CN,30,"Guangdong"
CN,31,"Hainan"
CN,32,"Sichuan"
CN,33,"Chongqing"
  GeoLiteCity.dat 更多变量请看 wiki 我这里只用到两个变量一个是$geoip_region  一个是$geoip_city_country   第一个是 地区,第二个变量是国家只取 两个字母简写!   geoip_city syntax: geoip_city path/to/db.dat; default: none context: http The directive indicates the path to the .dat file used for determining countries, regions and cities from IP-address of the client. When set the module makes available the following variables: $geoip_city_country_code; - two-letter country code, for example, "RU", "US". $geoip_city_country_code3; - three-letter country code, for example, "RUS", "USA". $geoip_city_country_name; - the name of the country, for example, "Russian Federation", "United States". $geoip_region; - the name of region (province, region, state, province, federal land, and the like), for example, "Moscow City", "DC". $geoip_city; - the name of the city, for example, "Moscow", "Washington". $geoip_postal_code; - postal code.   PS: 我只是根据南方电信,北方网通来区分的~~ 我是北京用户访问的是默认页面是因为我没有 把 22 数字填加到 配置文件里。我是为了方便测试!大家要是用在生产上要把 22加到    if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)")     网通里~  不过 开源的 geoip 还是有些不准确的~~~只能给他  75 分~~
本文出自 “linuxer” 博客,请务必保留此出处http://deidara.blog.51cto.com/400447/198469