nginx的缓存和第三方模块(Geoip)加载
2012-05-19 16:10
465 查看
运用nginx的第三方模块ngx_cache_purge和http_geoip_module(Geoip模块)
Geoip模块的作用主要是屏蔽某个地区的IP访问,系统自带的nginx一般不带这个模块,所以要下载nginx源代码后自行编译:
然后下载proxy_cache所需的模块ngx_cache_purge:
当安装好之后还需要下载IP 数据库
在nginx的http环境中中添加配置
这里并没有配置关于proxy_cache的事例,接着配置一个关于IP访问,通过Geoip模块获取得到如果是中国的IP就转向google
启动nginx,看下模块是否加载成功:
这样都是正常的,再访问打开的是跳到google就对了。
本文出自 “milanlinux” 博客,请务必保留此出处http://cclinux.blog.51cto.com/1215045/869190
Geoip模块的作用主要是屏蔽某个地区的IP访问,系统自带的nginx一般不带这个模块,所以要下载nginx源代码后自行编译:
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz tar zxvf GeoIP.tar.gz cd GeoIP-1.4.8/ ./configure make && make install echo '/usr/local/lib' > /etc/ld.so.conf ldconfig cd ../
然后下载proxy_cache所需的模块ngx_cache_purge:
wget http://labs.frickle.com/files/ngx_cache_purge-1.5.tar.gz tar zxf ngx_cache_purge-1.5.tar.gz
wget http://soft.vpser.net/web/pcre/pcre-8.12.tar.gz tar zxf pcre-8.12.tar.gz cd pcre-8.12 ./configure make && make install cd ../ wget http://nginx.org/download/nginx-1.0.10.tar.gz tar zxf nginx-1.0.10.tar.gz cd nginx-1.0.10 ./configure --user=www --group=www --add-module=../ngx_cache_purge-1.5 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_geoip_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 make && make install cd ../
当安装好之后还需要下载IP 数据库
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gunzip GeoIP.dat.gz 还有城市IP数据库详见: http://www.howtoforge.com/using-geoip-with-nginx-on-debian-squeeze-ubuntu-11.04
在nginx的http环境中中添加配置
http { ... geoip_country /path/to/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; ... }
这里并没有配置关于proxy_cache的事例,接着配置一个关于IP访问,通过Geoip模块获取得到如果是中国的IP就转向google
server { ····· if ($geoip_country_code ~ ^CN) { return http://www.google.com; } ······ }
启动nginx,看下模块是否加载成功:
/usr/local/nginx/sbin/nginx -V nginx: nginx version: nginx/1.0.10 nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52) nginx: TLS SNI support disabled nginx: configure arguments: --user=www --group=www --add-module=../ngx_cache_purge-1.5 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_geoip_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
这样都是正常的,再访问打开的是跳到google就对了。
本文出自 “milanlinux” 博客,请务必保留此出处http://cclinux.blog.51cto.com/1215045/869190
相关文章推荐
- nginx添加第三方模块
- Nginx 第三方模块-漫谈缘起
- nginx php动态编译加载模块.
- nginx 模块的加载和初始化
- 使用 Nginx 和 GeoIP 模块来处理不同国家的访问
- Nginx第三方模块安装
- nginx安装第三方模块的方法
- centos6.5生产环境编译安装nginx-1.11.3并增加第三方模块ngx_cache_purge、nginx_upstream_check、ngx_devel_kit、lua-nginx
- nginx利用第三方模块nginx_upstream_check_module来检查后端服务器的健康情况
- 玩玩 Nginx 2-----给Nginx添加第三方模块(动态更新upstream)
- 解剖Nginx·模块开发篇(4)模块开发中的命名规则和模块加载与运行流程
- 已安装的nginx添加第三方模块
- strip:nginx最让人吐槽的第三方模块
- nginx 平滑添加第三方模块
- nginx添加srcache-nginx模块进行页面缓存
- 使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
- nginx加载webdav模块实现http协议上传文件
- 如何安装nginx第三方模块
- nginx安装第三方模块
- thinkphp pathinfo nginx 无法加载模块:Index