饿虎岗资源网 Design By www.oxmxm.com
相信做过awstats的都用过开源的geoip.dat ip数据库,刚好nginx wiki上有geoip 模块,这样就可以实现地区性的负载均衡,但是maxmind 的ip数据库对中国的支持不算太好,不过现在也不错了~
参考文章:http://wiki.nginx.org/NginxHttpGeoIPModule
说下我的环境,我有一台美国linux 服务器,一台美国的windows 2003 ,一台本的XP。机器,其他测试用户都是,QQ群里的朋友,好了开始测试
linux : 75.125.x.x //美国
win2003 : 74.55.x.x // 美国
XP :localhost // 北京
测试转发,美国用户~转发到 www.google.cn
电信转发到 我的一台 公网的 apache 默认页面
网通转发到 我的一台 公网业务服务器!!
1.下载安装nginx.
shell $> get http://sysoev.ru/nginx/nginx-0.8.13.tar.gz
shell $> tar zxvf nginx-0.8.13.tar.gz
shell $> cd nginx-0.8.13
shell $>apt-get install libgeoip-dev
shell $> ./configure --prefix=/usr/local/nginx --with-http_flv_module --user=www --group=www --with-http_gzip_static_module --with-http_geoip_module
shell $> make
shell $> make install
2.下载GeoLiteCity.dat.gz 数据库~
shell $> wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
shell $> gzip -d GeoLiteCity.dat.gz
shell $> mv GeoLiteCity.dat /usr/local/nginx/conf/GeoLiteCity.dat
3.修改配置文件实现 地区性质负载
shell $> cd /usr/local/nginx/conf
shell $> cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
geoip_city GeoLiteCity.dat; upstream wangtong {
server 59.151.X.X;
}
upstream dianxin {
server 75.125.X.X;
}
upstream USA {
server www.google.cn;
} sendfile on; keepalive_timeout 65;
server {
listen 80;
server_name 75.125.197.200;
root html;
index index.html index.htm; location / {
if ($geoip_region ~ "(01|02|03|04|06|07|11|13|14|15|16|21|23|29|30|31|32|33)") {
proxy_pass http://dianxin$request_uri;
}
if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)") {
proxy_pass http://wangtong$request_uri;
}
if ($geoip_city_country_code ~ "US") {
proxy_pass http://USA$request_uri;
} }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} }
}
4.测试,用不同地方的机器做测试~ 我是北京用户,访问 我是北京用户访问的是默认页面是因为我没有 把 22 数字填加到 配置文件里。我是为了方便测试!大家要是用在生产上要把 22加到 if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)") 没有匹配到,就访问了默认页面~~ 成都朋友帮忙访问: 广州的朋友帮忙访问: 河北朋友帮忙访问: 美国 win2003 访问: 直接访问 电信的 服务器 和 网通服务器 59.151.X.X; 75.125.X.X; 直接访问 网通 59.151.X.X 直接访问 电信服务器 75.125.X.X 下面我来解释一下 if ($geoip_region ~ "(01|02|03|04|06|07|11|13|14|15|16|21|23|29|30|31|32|33)") 这些数字代表的是中国省份地区~~ 表如下: CN,01,"Anhui"
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
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
geoip_city GeoLiteCity.dat; upstream wangtong {
server 59.151.X.X;
}
upstream dianxin {
server 75.125.X.X;
}
upstream USA {
server www.google.cn;
} sendfile on; keepalive_timeout 65;
server {
listen 80;
server_name 75.125.197.200;
root html;
index index.html index.htm; location / {
if ($geoip_region ~ "(01|02|03|04|06|07|11|13|14|15|16|21|23|29|30|31|32|33)") {
proxy_pass http://dianxin$request_uri;
}
if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)") {
proxy_pass http://wangtong$request_uri;
}
if ($geoip_city_country_code ~ "US") {
proxy_pass http://USA$request_uri;
} }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} }
}
4.测试,用不同地方的机器做测试~ 我是北京用户,访问 我是北京用户访问的是默认页面是因为我没有 把 22 数字填加到 配置文件里。我是为了方便测试!大家要是用在生产上要把 22加到 if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)") 没有匹配到,就访问了默认页面~~ 成都朋友帮忙访问: 广州的朋友帮忙访问: 河北朋友帮忙访问: 美国 win2003 访问: 直接访问 电信的 服务器 和 网通服务器 59.151.X.X; 75.125.X.X; 直接访问 网通 59.151.X.X 直接访问 电信服务器 75.125.X.X 下面我来解释一下 if ($geoip_region ~ "(01|02|03|04|06|07|11|13|14|15|16|21|23|29|30|31|32|33)") 这些数字代表的是中国省份地区~~ 表如下: CN,01,"Anhui"
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
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年05月14日
2024年05月14日
- 鸣潮安可声骸怎么选择 安可声骸搭配及词条选择攻略
- 有线手柄比无线手柄更快乐 囧图 广东人怕热气吗?
- 一个命运多舛的IP!继动画后《宿命回响》手游也扑了
- 听说男人还有第三只脚?动图 此刻的保安是如此性福
- 邓伟标作品-太极头版限量编号HQII2022年【WAV+CUE】
- [ABC唱片]-《雪莉—白》[HDS-007][6N纯银镀膜CD][WAV+CUE]
- 【ABC唱片】《真空管HIFI录音大提琴》无力抗拒的音色[原抓WAV+CUE]
- 防不胜防!女子入住酒店在空调出风口发现摄像头
- 曝PS5 Pro或亮相PS发布会 《完美黑暗》进展不错
- 晨报|网易为《漫威争锋》预览合约道歉 《动物井》Steam好评如潮
- 群星《真开心3心情点播》台湾版[WAV+CUE][650MB]
- 世界杯《意大利之夏》1990意大利世界杯经典[WAV分轨][501M]
- 《郁可唯所有歌曲合集》[FLAC/MP3][6.2G]
- 群星.1995-离家·回家【中唱】【WAV+CUE】
- 陈雪凝.2018-拾陆【FLAC分轨】