首页 > 系统相关 >nginx模块ngx_http_geoip2_module

nginx模块ngx_http_geoip2_module

时间:2024-08-02 17:54:58浏览次数:10  
标签:http -- country module geoip2 nginx

/home/bby/nginx-1.26.0/modules/ngx_http_geoip2_module-3.4

 

./configure --prefix=/usr/local/nginx \
--with-compat \
--with-debug \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_sub_module \

 

1、先安装好 nginx
2、安装 ngx_http_geoip2_module 依赖库 sudo apt install libmaxminddb-dev

3、进入 nginx 源码目录
./configure --prefix=/usr/local/nginx \
--with-compat \
--with-debug \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--add-dynamic-module=/home/bby/ngx_http_geoip2_module

4、sudo make && sudo make install

编译完成会在:{nginx 源码目录}/objs/ngx_http_geoip2_module.so

如果没有 modules 文件夹,创建 /usr/local/nginx/modules
把这个 ngx_http_geoip2_module 目录拷贝到 /usr/local/nginx/modules/ngx_http_geoip2_module

 


---------- 配置 ----------
Nginx的http段添加下面配置
geoip2 /www/GeoLite2-City.mmdb {
$geoip_country_name default=unknown source=$http_x_real_ip country iso_code;
$geoip_province_name default=unknown source=$http_x_real_ip subdivisions 0 iso_code;
$geoip_city_name default=unknown source=$http_x_real_ip city names en;
}
map $geoip_country_name $allow_country {
CN 1; #这里的CN代表只允许中国地区访问
default 0;
}
map $geoip_province_name $allow_province {
HE 1; #这里的HE代表只允许河北地区访问
default 0;
}

三、修改nginx站点server段配置

Nginx的某站点server段添加下面配置

location / {
if ($allow_province = 0) {
return 403 "Forbidden";
}
}


---------- 配置 ----------
在http端中添加如下代码:
geoip2 /usr/local/share/GeoIP/GeoLite2-Country.mmdb {
$geoip2_data_country_code country iso_code;
}
map $geoip2_data_country_code $allowed_country {
default yes;
CN no;
}

if ($allowed_country = yes) {
return 403;
} 这里显示的是允许国内的ip访问,国外直接返回403
---------- 配置 ----------

标签:http,--,country,module,geoip2,nginx
From: https://www.cnblogs.com/fieldtianye/p/18339310

相关文章

  • iis安装数字证书ssl并实现http跳转https的301重定向
    iis安装数字证书ssl并实现http跳转https的301重定向为了增强网站的安全性,实现域名访问从HTTP自动跳转到HTTPS,您可以按照以下步骤操作:安装SSL证书:首先,您需要为您的网站获取一个SSL证书。这可以通过向证书颁发机构(CA)申请免费的证书(如Let'sEncrypt提供的证书)或购买商业证书来完成......
  • Oracle归档日志异常增长问题的排查过程 转载 : https://blog.csdn.net/3moods/article
    Oracle归档日志是Oracle数据库的重要功能,用于将数据库的重做日志文件(RedoLog)保存到归档日志文件(ArchiveLog)中。归档日志的作用是提供数据库的备份和恢复功能,以及支持数据库的持续性和数据完整性。当数据库处于归档模式时,数据库引擎会将已经写满的重做日志文件保存到归档日志文件......
  • Flutter 插件之http(介绍、使用、二次封装)
    背景在我们日常开发过程中,经常会使用到网络请求,而在Flutter插件中,最常用的请求插件一共两个,分别是:1、dio2、http其中dio我已经做过详细介绍了(post、get等请求、文件上传、请求重试等),这里就不做过多阐述,下面附上文章链接,如有需要可前往查看。https://blog.csdn.net/WangQin......
  • 使用 $fetch 进行 HTTP 请求
    title:使用$fetch进行HTTP请求date:2024/8/2updated:2024/8/2author:cmdragonexcerpt:摘要:文章介绍了Nuxt3中使用\(fetch进行HTTP请求的方法,它是基于ofetch库,支持SSR和自动缓存。\)fetch简化了HTTP请求,支持GET、POST等,可结合useAsyncData或useFetch优化数据获取,避......
  • JavaWeb(10) HTTP协议
    一、HTTP协议1.定义        HTTP超文本传输协议(HTTP-HyperTexttransferprotocol),是一个属于应用层的面向对象的协议,由于其简捷、快速的方式,适用于分布式超媒体信息系统。它于1990年提出,经过十几年的使用与发展,得到不断地完善和扩展。它是一种详细规定了浏览器......
  • tpmtool 描述:     此实用程序可用于获取有关受信任的平台模块(TPM)的信息。    
     tpmtool|MicrosoftLearntpmtool描述:  此实用程序可用于获取有关受信任的平台模块(TPM)的信息。  有关最新文档,请转到https://aka.ms/tpmtool语法:  tpmtool[parameter][<参数>]参数:  GETDEVICEINFORMATION          显示......
  • 小程序http封装
    constui=require('./ui');constBASE_URL='http://119.23.227.211:8011'/***网络请求request*obj.data请求接口需要传递的数据*obj.showLoading控制是否显示加载Loading默认为false不显示*obj.contentType默认为application/json*obj.method请求......
  • bezier_align_forward miss in module _ext
    t_utils.py",line453,in_get_moduleraiseRuntimeError(RuntimeError:Failedtoimportmodelscope.models.cv.image_human_parsing.m2fp_netbecauseofthefollowingerror(lookuptoseeitstraceback):bezier_align_forwardmissinmodule_ext遇到&qu......
  • Http发送Post请求 form-data 和 application/x-www-form-urlencoded 区别
    在HTTP协议中,使用POST请求时,可以通过不同的方式发送表单数据。form-data 和 application/x-www-form-urlencoded是两种常见的编码方式,它们在发送数据时有一些关键的区别:application/x-www-form-urlencoded编码方式:以键值对的形式进行编码,每个键值对之间用&符号连接,每个键和值......
  • 将 HTTP 分块编码数据流代码片段从 Node.js 转换为 Python
    我有一个Node.js客户端代码,它将请求发送到HTTP服务器,然后连续接收分块编码数据。这是带有一些流量数据输出的Node.js代码。consthttp=require('http');constoptions={hostname:'...',path:'...',port:...,...};constreq=http.request(......