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读取地域信息模块的更多相关文章

  1. nginx应用geoip模块,实现不同地区访问不同页面的需求(实践版)

    https://www.52os.net/articles/configure-nginx-using-geoip-allow-whitelist.html       搞了几天没有搞定,这篇文章一下 ...

  2. 使用 Nginx 和 GeoIP 模块来处理不同国家的访问

    安装 Nginx因为要用到 http_geoip_module 模块,系统自带的 nginx 一般不带这个模块,所以要下载 nginx 源代码后自行编译: # wget http://nginx.or ...

  3. Nginx结合GeoIP库

    1. 编译nginx时带上geoip模块 # wget http://nginx.org/download/nginx-x.x.x.tar.gz # tar zxvf nginx-x.x.x.tar. ...

  4. nginx请求体读取(二)

    2,丢弃请求体 一个模块想要主动的丢弃客户端发过的请求体,可以调用nginx核心提供的ngx_http_discard_request_body()接口,主动丢弃的原因可能有很多种,如模块的业务逻辑压 ...

  5. nginx请求体读取

    上节说到nginx核心本身不会主动读取请求体,这个工作是交给请求处理阶段的模块来做,但是nginx核心提供了ngx_http_read_client_request_body()接口来读取请求体,另外 ...

  6. Nginx使用GeoIP模块来限制地区访问

    举例比如限制泰国地区的IP访问: 前提条件,安装了http geoip 或stream geoip模块的Nginx Plus或者开源nginx Maxmind的GeoLite Legacy数据库 1. ...

  7. Nginx 下无法读取session 导致 thinkphp验证码错误

    打开php配置文件 php.ini 使用搜索命令 whereis php.ini 一般在:/etc/php.ini 目录下 使用vim命令打开 找到: session.save_path 找到php保 ...

  8. Nginx模块GeoIP匹配处理IP所在国家、城市

    https://www.haiyun.me/archives/nginx-geoip.html

  9. nginx 场景业务汇总 (初)

    本文链接:http://www.cnblogs.com/zhenghongxin/p/8891385.html 在下面的测试中,建议每次修改nginx配置文件后,都用此命令检查一下语法是否正确: [r ...

随机推荐

  1. 机器学习实战-Logistics回归

    Logistics回归:实战,有两个特征X0,X1.100个样本,进行Logistics回归 1.导入数据 def load_data_set(): """ 加载数据集 ...

  2. python 并发编程 多进程 Process对象的其他属性方法 join 方法

    一 Process对象的join方法 在主进程运行过程中如果想并发地执行其他的任务,我们可以开启子进程,此时主进程的任务与子进程的任务分两种情况 情况一: 在主进程的任务与子进程的任务彼此独立的情况下 ...

  3. 第三次实验报告&&学习总结

    实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 1.已知字符串:"this is a test of java".按要求执 ...

  4. for语句与if语句嵌套的简单应用

    1.循环语句 for(初始条件:循环条件:状态改变) { 循环体 } break为跳出循环,continue为结束此次循环. 2.死循环常用while语句 while(判断语句) { if(判断) { ...

  5. 005 gcc 的简单使用

    0. 前言 本文主要讲关于 gcc 的几种编译方式 不妨设文件名为 test.c 1. 方法一 $ gcc test.c (Windows OS)编译成功的话,没有回馈,在 test.c 所在的文件夹 ...

  6. 高级BASH

    Bash介绍与入门 1,简介 Bash(GNU Bourne-Again Shell)是一个为GNU计划编写的Unix shell,它是许多Linux平台默认使用的shell shell是一个命令解释 ...

  7. Luogu P4040 [AHOI2014/JSOI2014]宅男计划

    题目 显然存活天数与叫外卖次数的函数是凸函数. 所以三分买外卖的次数. 然后把食品按保质期升序排序. 并且单调栈搞一下,把又贵又保质期短的丢掉. 那么随着保质期的增加,食品的价格一定上涨. 所以我们从 ...

  8. Vue 变量,成员,属性监听

    Vue变量 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...

  9. String.IsNullOrEmpty官方示例

    // This example demonstrates the String.IsNullOrEmpty() method using System; class Sample { public s ...

  10. VB.net删除节点,数据库,文件

    Private Sub mnuDel_Click()'删除节点Dim sKey As String'Dim sFile As StringDim oFS As FileSystemObjectDim ...