亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Nginx geoip模塊實(shí)現(xiàn)地區(qū)性負(fù)載均衡

 更新時(shí)間:2010年12月22日 13:51:58   作者:  
相信做過(guò)awstats的都用過(guò)開(kāi)源的geoip.dat ip數(shù)據(jù)庫(kù),剛好nginx wiki上有g(shù)eoip 模塊,這樣就可以實(shí)現(xiàn)地區(qū)性的負(fù)載均衡,但是maxmind 的ip數(shù)據(jù)庫(kù)對(duì)中國(guó)的支持不算太好,不過(guò)現(xiàn)在也不錯(cuò)了~
相信做過(guò)awstats的都用過(guò)開(kāi)源的geoip.dat  ip數(shù)據(jù)庫(kù),剛好nginx wiki上有g(shù)eoip 模塊,這樣就可以實(shí)現(xiàn)地區(qū)性的負(fù)載均衡,但是maxmind 的ip數(shù)據(jù)庫(kù)對(duì)中國(guó)的支持不算太好,不過(guò)現(xiàn)在也不錯(cuò)了~
參考文章:http://wiki.nginx.org/NginxHttpGeoIPModule
 
說(shuō)下我的環(huán)境,我有一臺(tái)美國(guó)linux 服務(wù)器,一臺(tái)美國(guó)的windows 2003 ,一臺(tái)本的XP。機(jī)器,其他測(cè)試用戶都是,QQ群里的朋友,好了開(kāi)始測(cè)試
linux : 75.125.x.x                    //美國(guó)
win2003 : 74.55.x.x                // 美國(guó)
XP :localhost                     // 北京
 
測(cè)試轉(zhuǎn)發(fā),美國(guó)用戶~轉(zhuǎn)發(fā)到 www.google.cn
電信轉(zhuǎn)發(fā)到 我的一臺(tái) 公網(wǎng)的 apache 默認(rèn)頁(yè)面
網(wǎng)通轉(zhuǎn)發(fā)到  我的一臺(tái) 公網(wǎng)業(yè)務(wù)服務(wù)器??!
 
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 數(shù)據(jù)庫(kù)~
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.修改配置文件實(shí)現(xiàn) 地區(qū)性質(zhì)負(fù)載
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.測(cè)試,用不同地方的機(jī)器做測(cè)試~
我是北京用戶,訪問(wèn)
 
我是北京用戶訪問(wèn)的是默認(rèn)頁(yè)面是因?yàn)槲覜](méi)有 把 22 數(shù)字填加到 配置文件里。我是為了方便測(cè)試!大家要是用在生產(chǎn)上要把 22加到
 
 if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)")  
沒(méi)有匹配到,就訪問(wèn)了默認(rèn)頁(yè)面~~
 
成都朋友幫忙訪問(wèn):
 
廣州的朋友幫忙訪問(wèn):
 
河北朋友幫忙訪問(wèn):
 
美國(guó) win2003 訪問(wèn):
 
直接訪問(wèn) 電信的 服務(wù)器 和 網(wǎng)通服務(wù)器
 
59.151.X.X;    75.125.X.X;
 
直接訪問(wèn)  網(wǎng)通 59.151.X.X
 
直接訪問(wèn) 電信服務(wù)器 75.125.X.X
 
 
下面我來(lái)解釋一下
if ($geoip_region ~ "(01|02|03|04|06|07|11|13|14|15|16|21|23|29|30|31|32|33)")
 
這些數(shù)字代表的是中國(guó)省份地區(qū)~~
表如下:
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 更多變量請(qǐng)看 wiki 我這里只用到兩個(gè)變量一個(gè)是$geoip_region  一個(gè)是$geoip_city_country   第一個(gè)是 地區(qū),第二個(gè)變量是國(guó)家只取 兩個(gè)字母簡(jiǎn)寫!
 
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: 我只是根據(jù)南方電信,北方網(wǎng)通來(lái)區(qū)分的~~ 我是北京用戶訪問(wèn)的是默認(rèn)頁(yè)面是因?yàn)槲覜](méi)有 把 22 數(shù)字填加到 配置文件里。我是為了方便測(cè)試!大家要是用在生產(chǎn)上要把 22加到
 
 if ($geoip_region ~ "(05|08|09|10|12|17|18|19|20|24|25|26)")  
 
網(wǎng)通里~  不過(guò) 開(kāi)源的 geoip 還是有些不準(zhǔn)確的~~~只能給他  75 分~~
本文出自 “l(fā)inuxer” 博客,請(qǐng)務(wù)必保留此出處http://deidara.blog.51cto.com/400447/198469

相關(guān)文章

最新評(píng)論