nginx中Geoip_module模块的使用
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>
nginx中Geoip_module模块的使用的更多相关文章
- Nginx中ngx_http_proxy_module模块
该模块允许将请求传递给另⼀一台服务器器指令:1 ,proxy_pass设置代理理服务器器的协议和地址以及应映射位置的可选 URI .作为协议,可以指定“ http 或 https .可以将地址指定为域 ...
- nginx中ngx_http_core_module模块
http核⼼心模块指令:套接字相关的配置3.1 server{ }设置虚拟服务器器的配置Syntax: server { ... }Default: —Context: httpserver {lis ...
- Nginx中location模块的详细配置(含示例)
题记 此前在配置Nginx location模块的时候玩出了一些bug,折腾了一段时间.后来网上也查阅了相关的资料,看着也比较混乱.周末有空想着好好整理一下location模块的配置,结合自己的亲手实 ...
- nginx中ngx_http_ssl_module模块
此模块为HTTPS提供必要的⽀支持worker_processes auto;http {...server {listen 443 ssl;keepalive_timeout 70;ssl_prot ...
- nginx中ngx_http_gzip_module模块
⽤用gzip⽅方法压缩响应数据,节约带宽gzip on;gzip_min_length 1000;gzip_proxied expired no-cache no-store private auth ...
- nginx中的模块分类及常见核心模块有哪些
1.模块分类 核心模块:是 Nginx 服务器正常运行必不可少的模块,提供错误日志记录 .配置文件解析 .事件驱动机制 .进程管理等核心功能 标准HTTP模块:提供 HTTP 协议解析相关的功能,比如 ...
- Nginx中ngx_http_upstream_module模块
用于将多个服务器器定义成服务器器组,⽽而由 proxy_pass , fastcgi_pass 等指令进⾏行行引⽤用upstream backend {server backend1.example. ...
- Nginx中ngx_http_log_module模块
指定⽇日志格式记录请求指令: access_log设置缓冲⽇日志写⼊入的路路径,格式和配置Syntax: access_log path [format[buffer=size] [gzip[=lev ...
- nginx中ngx_http_access_module模块
实现基于IP的访问控制功能指令:4.1 allow允许访问指定的⽹网络或地址Syntax: allow address | CIDR | unix:| all;Default: —Context: h ...
随机推荐
- JQuery和ASP.NET分别实现级联下拉框效果
在学习JQuery之前知道下拉框的级联效果可以通过asp.net控件实现,现在学习了JQuery,知道了JQuery和select也能实现.我分别举两个小例子说明这两种方法如何实现. 1.用JQuer ...
- redhat开启端口
设置端口:sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT 或 /etc/init.d/iptables -I INPUT -p tc ...
- python 精华梳理(已理解并手写)--全是干货--已结
基础部分 map,reduce,filter,sort,推导式,匿名函数lambda , 协程,异步io,上下文管理 自定义字符串转数字方法一不使用reduce import re def str2i ...
- 31.【微服务架构】SpringCloud之Feign(五)
Feign简介 Feign 是一个声明web服务客户端,这便得编写web服务客户端更容易,使用Feign 创建一个接口并对它进行注解,它具有可插拔的注解支持包括Feign注解与JAX-RS注解,Fei ...
- FFI
FFI概念 https://segmentfault.com/t/ffi/info FFI即Foreign Function Interface,外部函数调用接口,是一个语言提供的使用其他语言现有库( ...
- JSON CSRF新姿势
以前做渗透测试,遇到过很多次POST数据为JSON数据的CSRF,一直没有搞定,最近发现一个新姿势, 本文作者:Mannix@安全文库 微信公众号:安全文库 测试的时候,当应用程序验证了Cont ...
- [机器学习笔记]奇异值分解SVD简介及其在推荐系统中的简单应用
本文先从几何意义上对奇异值分解SVD进行简单介绍,然后分析了特征值分解与奇异值分解的区别与联系,最后用python实现将SVD应用于推荐系统. 1.SVD详解 SVD(singular value d ...
- ubuntu安装GBK编码
1 添加GBK编码 sudo vim /var/lib/locales/supported.d/local en_US.UTF-8 UTF-8 zh_CN.UTF-8 UTF-8 zh_CN.GBK ...
- Dan版本的nnet2
除了chain,nnet1, nnet2, nnet3训练时调整转移模型,chain模型使用类似与MMI的训练准则 Dan's setup does not uses pre-training. Da ...
- Eclipse 自动生成 Ant的Build.xml 配置文件
Eclipse 自动生成 Ant的Build.xml 配置文件,生成的方法很隐蔽 选择你要生成Build.xml文件的项目,右键. Export-> General -> Ant Buil ...