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 ...
随机推荐
- 未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker
昨晚遇到的这个问题,也知道Notifications service依赖底层的Service broker的.本以为只需要执行以下脚本对数据库启用Service broker即可. alter dat ...
- telnet客户端程序
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types. ...
- 【51nod 1100】斜率最大
Description 平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点. (点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标 ...
- MySQL之数据表的插入内容 空与非空(六)
NULL与NOT NULL mysql> CREATE TABLE tb2( -> usename VARCHAR(20) NOT NULL, -> age TINYINT UNSI ...
- python函数后面有多个括号怎么理解?
一般而言,函数后面只有一个括号.如果看见括号后还有一个括号,说明第一个函数返回了一个函数,如果后面还有括号,说明前面那个也返回了一个函数.以此类推. 比如fun()() def fun(): prin ...
- Java SE之正则表达式五:切割
/** * * @author Zen Johnny * @date 2018年4月29日 下午3:53:55 * */ package demo.regex; /* 正则表达式:切割 */ publ ...
- 使用Python的turtle库画圣诞树
代码如下: from turtle import * import random import time n = 80.0 speed("fastest") screensize( ...
- 洛谷P1494 【[国家集训队]小Z的袜子】
纪念自己独立完成的一道省选题(菜鸡如我只会看题解qwq) 还算是一道比较裸的莫队题把,比有的题目简单很多,也很好想怎么O(1)转移,比别的题就多了一个组合数计算(还有gcd??),还没算%意义下,也是 ...
- [css]将textarea前的文字设置在左上角
在使用textarea的时候,默认前面的文字是在最下面的,好丑,然后百度了一下,要在textarea加上vertical-align:top的css属性 代码: <div class=" ...
- LOJ #2542「PKUWC2018」随机游走
$ Min$-$Max$容斥真好用 $ PKUWC$滚粗后这题一直在$ todolist$里 今天才补掉..还要更加努力啊.. LOJ #2542 题意:给一棵不超过$ 18$个节点的树,$ 5000 ...