现在的位置: 首页 > 综合 > 正文

nginx 配置 geoip模块以及nginx启动命令

2013年10月09日 ⁄ 综合 ⁄ 共 1547字 ⁄ 字号 评论关闭

1:下载支持with-http_geoip_module的nginx(1.1.17)版本 下载地址:http://nginx.org/download/

 

2:安装nginx ,安装命令: tar zxvf nginx1.1.17文件名称

 

3: 安装 MaxMind 的 GeoIP 库

MaxMind 提供了免费的 IP 地域数据库(GeoIP.dat),不过这个数据库文件是二进制的,需要用 GeoIP 库来读取,所以除了要下载 GeoIP.dat 文件外(见下一步),还需要安装能读取这个文件的库。

 

# wgethttp://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz

# tar -zxvf GeoIP.tar.gz

# cd GeoIP-1.4.6

# ./configure

# make; make install

刚才安装的库自动安装到/usr/local/lib 下,所以这个目录需要加到动态链接配置里面以便运行相关程序的时候能自动绑定到这个 GeoIP 库:

 

# echo '/usr/local/lib' >/etc/ld.so.conf.d/geoip.conf

# ldconfig

 

4:编译with-http_geoip_module,具体操作:
# cd nginx-1.1.17
# ./configure --with-http_geoip_module
 

5:如果第四步操作遇到编译错误,如果是无法找到库文件,可以使用

yum list |grep  zlib  查看库文件,

然后yum install zlib_deve来进行安装

缺少 pcre和gcc 使用 yum installpcre yum install gcc 来进行安装

 

6:下载ip包

# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# gunzip GeoIP.dat.gz

 

 

7:配置nginx 编辑nginx的nginx.conf 文件:

 

http {
...
geoip_country /home/vpsee/GeoIP.dat;
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;//可以根据自己的需要来选择是否需要此参数
fastcgi_param GEOIP_COUNTRY_NAME  $geoip_country_name; //可以根据自己的需要来进行设置
 
...
}
 
server {
...
        location / {
            root   /home/vpsee/www;
            if ($geoip_country_code = CN) {
                root /home/vpsee/cn;
            }
            ...
        }
...
}

 

nginx启动命令

/usr/local/nginx/sbin/nginx–t //测试

 

/usr/local/nginx/sbin/nginx–s stop//停止

/usr/local/nginx/sbin/nginx–s reopen//重启

/usr/local/nginx/sbin/nginx–s reload//重启

 

) Linux操作系统中永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后复原

开启: service iptables start

关闭: service iptables stop

 

抱歉!评论已关闭.