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

2019-10-17 21:20:25刘景俊
相信做过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 / {