Nginx geoip模塊實現地區性負載均衡
2024-08-30 12:27:18
供稿:網友
相信做過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.gzshell $> tar zxvf nginx-0.8.13.tar.gzshell $> cd nginx-0.8.13shell $>apt-get install libgeoip-devshell $> ./configure --prefix=/usr/local/nginx --with-http_flv_module --user=www --group=www --with-http_gzip_static_module --with-http_geoip_moduleshell $> make shell $> make install 2.下載GeoLiteCity.dat.gz 數據庫~shell $> wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzshell $> gzip -d GeoLiteCity.dat.gzshell $> mv GeoLiteCity.dat /usr/local/nginx/conf/GeoLiteCity.dat 3.修改配置文件實現 地區性質負載shell $> cd /usr/local/nginx/confshell $> cat nginx.confworker_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 / {