博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx之Geoip读取地域信息模块
阅读量:6895 次
发布时间:2019-06-27

本文共 1586 字,大约阅读时间需要 5 分钟。

1 geoip_module模块

基于IP地址匹配MaxMind GeolP二进制文件,读取IP所在地域信息。

yum install nginx-module-geoip

geoip2已经有了,安装另寻

2、http_geoip_module使用

一、区别国内外作HTTP访问规则

二、区别国内城市地域作HTTP访问规则

用到的ip数据库

链接:https://pan.baidu.com/s/1KcFhouFhP7jQOEZaZutMtw  提取码:okjp

vim nginx.confload_module modules/ngx_http_geoip_module.so;   #导入模块load_module modules/ngx_stream_geoip_module.so;​user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;include /usr/share/nginx/modules/*.conf;events {    worker_connections 1024;}http {    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;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;​    include /etc/nginx/conf.d/cp5/*.conf;}​cat conf.d/cp5/test_geoip.confgeoip_country /etc/nginx/geoip/GeoIP.dat;       #geoip_city /etc/nginx/geoip/GeoLiteCity.dat;# geoip_country /tmp/geoip/GeoLite2-Country/GeoLite2-Country.mmdb;# geoip_city /tmp/geoip/GeoLite2-City/GeoLite2-City.mmdb;server {    listen       80;    server_name  web01.fadewalk.com;​    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";   }}
 
 

测试

转载于:https://www.cnblogs.com/wenyule/p/11071800.html

你可能感兴趣的文章
Memcached管理与监控工具 MemAdmin
查看>>
mysql 主从复制读写分离
查看>>
在百花之中干掉一个杂草连接...
查看>>
HTML文档基本格式
查看>>
for 循环的关键字 break和continue
查看>>
Map集合的四种遍历方式
查看>>
MySQL监控项一些指标
查看>>
Thinkpad T430s NVS5400M Ubuntu 12.04安装
查看>>
定时拍照功能
查看>>
[Unity3d]SecurityException报错解决办法
查看>>
SCVMM创建Linux虚拟机模版
查看>>
添加 Pool Member - 每天5分钟玩转 OpenStack(123)
查看>>
NSDECODER v1.0
查看>>
游侠原创:vmware下android-x86-4.4-RC1体验
查看>>
OpenMNS--管理网络的绝好工具
查看>>
ORACLE LINUX 6.1安装过程
查看>>
iPhone/Mac Objective-C内存管理原理
查看>>
整理Silverlight资源列表(三)-SL实际运用案例
查看>>
02-BGP选路原则和属性详解--weight
查看>>
7.[数据结构和算法分析笔记]词典 Dictionary
查看>>