nginx中Geoip_module模块的使用

.安装模块,nginx也是通过yum安装
yum install nginx-module-geoip -y # 可以看到模块的链接库文件
[root@test8_hadoop_kaf modules]# pwd
/etc/nginx/modules
[root@test8_hadoop_kaf modules]# ls
ngx_http_geoip_module-debug.so ngx_stream_geoip_module-debug.so
ngx_http_geoip_module.so ngx_stream_geoip_module.so 下载ip库信息文件并放在/etc/nginx/geoip/目录
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz [root@test8_hadoop_kaf conf.d]# mkdir -p /etc/nginx/geoip/
[root@test8_hadoop_kaf ~]# gunzip GeoIP.dat.gz
[root@test8_hadoop_kaf ~]# gunzip GeoLiteCity.dat.gz
[root@test8_hadoop_kaf ~]# mv *.dat /etc/nginx/geoip/ .Nginx.conf全局配置中添加 load_module /usr/lib64/nginx/modules/ngx_http_geoip_module.so; 配置 [root@test8_hadoop_kaf conf.d]# cat ../nginx.conf user nginx;
worker_processes ;
load_module /usr/lib64/nginx/modules/ngx_http_geoip_module.so; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections ;
} http {
include /etc/nginx/mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout ;
#gzip on; include /etc/nginx/conf.d/*.conf;
} 3.配置访问接口
[root@test8_hadoop_kaf conf.d]# cat geo_test.conf
geoip_country /etc/nginx/geoip/GeoIP.dat;
geoip_city /etc/nginx/geoip/GeoLiteCity.dat; server{
listen 80;
server_name localhost; location / {
if ($geoip_country_code != CN) {
return 403;
} root /usr/share/nginx/html;
index index.html index.htm;
} location /myip {
default_type text/plain;
return 200 "$remote_addr $geoip_country_name $geoip_country_code $geoip_city";
}
}

国内测试

在国外测试
[root@u04mix03 ~]# curl http://es.chinasoft.com/myip
107.150.X.X United States US Los Angeles

[root@u04mix03 ~]# curl http://es.yayaim.com
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>

最新文章

  1. Unity3D中使用委托和事件
  2. 导出HTML
  3. CLR via C#(18)——Enum
  4. C语言语法之运算符及优先级
  5. Java 实现任意N阶幻方的构造
  6. 【WCF 2】理解WCF框架的简单小实例
  7. 在mybatis执行SQL语句之前进行拦击处理
  8. 第一节:Maven 下载,安装和配置
  9. Oracle执行计划——使用index full scan的几种情况
  10. CentOS下安装Nginx并添加nginx_upload_module
  11. 1_Two Sum --LeetCode
  12. SOA和微服务架构
  13. 汉明码(Hamming)编码与纠错原理
  14. 进程&amp;线程(转)
  15. [ZJOI2009]函数 题解
  16. Python(字符编码)
  17. darknet集成遇到的问题以及解决方法
  18. 使用IDE之webstorm
  19. Ubunt 使用Virtualbox虚拟机NAT无法上网解决办法
  20. cocos2dx 常用的构建工具

热门文章

  1. 【leetcode-73】 矩阵置零
  2. 【leetcode-86】 分隔链表
  3. solr简介与安装
  4. [Android] Android最简单ScrollView和ListView滚动冲突解决方案
  5. Photoshop影像匀色技术
  6. C# 异步方法(AM)
  7. gethostbyname和gethostbyaddr
  8. Mono.Cecil
  9. 【noip 2012】提高组Day2T3.疫情控制
  10. 20155324 《Java程序设计》实验四 Android开发基础