nginx之Geoip读取地域信息模块
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.conf
load_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.conf
geoip_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";
} }
测试

nginx之Geoip读取地域信息模块的更多相关文章
- nginx应用geoip模块,实现不同地区访问不同页面的需求(实践版)
https://www.52os.net/articles/configure-nginx-using-geoip-allow-whitelist.html 搞了几天没有搞定,这篇文章一下 ...
- 使用 Nginx 和 GeoIP 模块来处理不同国家的访问
安装 Nginx因为要用到 http_geoip_module 模块,系统自带的 nginx 一般不带这个模块,所以要下载 nginx 源代码后自行编译: # wget http://nginx.or ...
- Nginx结合GeoIP库
1. 编译nginx时带上geoip模块 # wget http://nginx.org/download/nginx-x.x.x.tar.gz # tar zxvf nginx-x.x.x.tar. ...
- nginx请求体读取(二)
2,丢弃请求体 一个模块想要主动的丢弃客户端发过的请求体,可以调用nginx核心提供的ngx_http_discard_request_body()接口,主动丢弃的原因可能有很多种,如模块的业务逻辑压 ...
- nginx请求体读取
上节说到nginx核心本身不会主动读取请求体,这个工作是交给请求处理阶段的模块来做,但是nginx核心提供了ngx_http_read_client_request_body()接口来读取请求体,另外 ...
- Nginx使用GeoIP模块来限制地区访问
举例比如限制泰国地区的IP访问: 前提条件,安装了http geoip 或stream geoip模块的Nginx Plus或者开源nginx Maxmind的GeoLite Legacy数据库 1. ...
- Nginx 下无法读取session 导致 thinkphp验证码错误
打开php配置文件 php.ini 使用搜索命令 whereis php.ini 一般在:/etc/php.ini 目录下 使用vim命令打开 找到: session.save_path 找到php保 ...
- Nginx模块GeoIP匹配处理IP所在国家、城市
https://www.haiyun.me/archives/nginx-geoip.html
- nginx 场景业务汇总 (初)
本文链接:http://www.cnblogs.com/zhenghongxin/p/8891385.html 在下面的测试中,建议每次修改nginx配置文件后,都用此命令检查一下语法是否正确: [r ...
随机推荐
- STM32 USB开发(三) 基于F105RBT6核心板开发的自定义HID收发(FS)
硬件设计 该核心板的USB插口有两个,一个是用于USB Slave的,可以用来做HID设备,把模拟STM32模拟为U盘等:另一个是USB Host设备,可以对插上的U盘的数据进行读写. 图中J2是Mi ...
- 【Qt开发】QT样式表单 qss的样式优化
QT样式表单 QT的样式表单允许我们在对程序不做任何代码上的更改的情况下轻松改变应用程序的外观. 其思想来源于网页设计中的CSS,即可以将功能设计和美学设计分开. 它的语法和概念和HTML CSS也是 ...
- 【Qt开发】Qt在Windows下的三种编程环境搭建
从QT官网可以得知其支持的平台.编译器和调试器的信息如图所示: http://qt-project.org/doc/qtcreator-3.0/creator-debugger-engines.htm ...
- .net core 学习小结之 自定义JWT授权
自定义token的验证类 using System; using System.Collections.Generic; using System.IO; using System.Linq; usi ...
- HTTP请求状态码为400时的原因
2019-11-30 出现这个请求无效说明请求没有进入后台服务器里 原因: (1)前端提交的字段名称或者字段类型和后台的实体类不一样 或者前端提交的参数跟后台需要的参数个数不一致,导致无法封装 (2) ...
- 2019年安徽大学ACM/ICPC实验室新生赛(公开赛)D 不定方程
题目链接:https://ac.nowcoder.com/acm/contest/2720/D 题意:对于 ax = by = c ,给出 x, y 求符合条件的 a, b, c 且 c 为最小的解, ...
- 使用electron实现百度网盘悬浮窗口功能!
相关依赖 里面使用了vuex vue vue-route storeJs storeJs 用来持久化vuex状态 展示 介绍说明 没有使用electron内置的-webkit-app-region: ...
- django -----原生SQL语句查询与前端数据传递?
view.py中 import MySQL def request_data(request): if request.method == "GET": conn = MySQLd ...
- 如何将数据库导入到本地MySQL
有两个方法:(1)在MySQL的客户端进行导入,比如: http://jingyan.baidu.com/article/6dad507517c11aa123e36ea0.html (2)方法:常用s ...
- 使nginx归于systemd管理
[root@centos7 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=The Nginx HTTP Server ...