欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

相關文章

最新評論