百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> Nginx中调用GeoIP2的拓展模块处理不同国家的访问
分享文章到:

Nginx中调用GeoIP2的拓展模块处理不同国家的访问

发布时间:01/15 来源: 浏览: 关键词:
GeoIP2是一个IP库了可以获得访问者IP地址的地量位置信息了,我们可以根据IP来设置不同访问进行到不同的IP地址,具体设置如下。

下面为Nginx安装配置

(1)需要先安装libmaxminddb依赖库。libmaxminddb是一个C库文件,用于读取MaxMind DB文件,包括MaxMind下的GeoIP2数据文件。

$ cd /usr/local/src
$ git clone --recursive https://github.com/maxmind/libmaxminddb
$ cd libmaxminddb
$ ./bootstrap
$ ./configure
$ make
$ make install
$ sh -c "echo /usr/local/lib  >> /etc/ld.so.conf.d/local.conf"
$ ldconfig
(2)重新编译ngx_http_geoip2_module模块。原Nginx带的–with-http_geoip_module用的是使用的是第一代Geoip(geoip1)。现在geoip2还未加入模块中。


#获取ngx_http_geoip2_module
#cd /usr/local/src && git clone --recursive https://github.com/leev/ngx_http_geoip2_module
#查看原nginx编译参数
# nginx -V
nginx version: nginx/1.6.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/opt/webserver/nginx --without-http_memcached_module --user=www --group=www --with-http_image_filter_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 --with-http_sub_module --add-module=/usr/local/src/nginx-accesskey-2.0.3  --with-http_realip_module --with-http_mp4_module
#添加模块、重新编译编译nginx
#cd /usr/local/src/nginx-1.6.2 &&
./configure --prefix=/opt/webserver/nginx \
--without-http_memcached_module \
--user=www \
--group=www \
--with-http_image_filter_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-openssl=/usr/local/src/openssl-1.0.1j \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-pcre=/usr/local/src/pcre-8.36 \
--with-http_sub_module \
--add-module=/usr/local/src/nginx-accesskey-2.0.3 \
--add-module=/usr/local/src/ngx_http_geoip2_module \
--with-http_realip_module \
--with-http_mp4_module  &&
make
#备份原nginx程序文件
#mv /opt/webserver/nginx/sbin/nginx /opt/webserver/nginx/sbin/nginx.bak &&
\cp objs/nginx /opt/webserver/nginx/sbin/nginx &&
nginx -t
#测试没有问题,升级nginx
#make upgrade

(3)简单配置nginx.conf示例

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有3人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板