centos 7 上为nginx 增加Geo IP的功能

yum install gcc gcc-c++ make automake autoconf libtool wget unzip -y

if [ ! -d "/usr/local/software" ]; then mkdir /usr/local/software
fi
cd /usr/local/software if [ ! -f "/usr/local/software/libmaxminddb-1.3.2.tar.gz" ]; then
wget http://download.zhufunin.com/libmaxminddb-1.3.2.tar.gz
fi if [ ! -f "/usr/local/software/ngx_http_geoip2_module.zip" ]; then
wget http://download.zhufunin.com/ngx_http_geoip2_module.zip
fi if [ ! -f "/usr/local/software/maxmind-city.mmdb.tar.gz" ]; then
wget http://download.zhufunin.com/maxmind-city.mmdb.tar.gz
fi tar zxvf libmaxminddb-1.3..tar.gz
tar zxvf maxmind-city.mmdb.tar.gz
unzip -o ngx_http_geoip2_module.zip cd ./libmaxminddb-1.3.
./configure
make && make install
[[ -z `cat /etc/ld.so.conf |grep "\/usr\/local\/lib"` ]] && echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

安装nginx的时候

./configure \

...

--add-module=/usr/local/software/ngx_http_geoip2_module-master \

...

在nginx 配置http的位置添加以下配置,maxmind-city.mmdb IP库需要放到/usr/local/nginx/geoip/下面

fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME $geoip2_data_city_name; geoip2 /usr/local/nginx/geoip/maxmind-city.mmdb {
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
$geoip2_data_country_name country names en;
$geoip2_data_city_name default=London city names en;
$geoip2_data_province_name subdivisions names en;
$geoip2_data_province_isocode subdivisions iso_code;
}

maxmind IP 库更新脚本,可以放到crontab 中定期运行,更新IP库

#!/bin/bash
cd /usr/local/nginx/geoip/
rm -rf /usr/local/nginx/geoip/GeoLite2-City_*
rm -rf /usr/local/nginx/geoip/GeoLite2-City.tar.gz*
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
code="$?"
echo $code
if test "$code" -ne ;then
echo "Download is failed"
exit ;
fi
tar zxf GeoLite2-City.tar.gz
cd GeoLite2-City_*
if test ! -e GeoLite2-City.mmdb; then
exit ;
fi
size=`du -s ./GeoLite2-City.mmdb |awk '{print $1}'`
if test "$size" -lt ;then
exit ;
fi
echo "mv GeoLite2-City.mmdb maxmind-city.mmdb"
mv GeoLite2-City.mmdb maxmind-city.mmdb
echo "mv maxmind-city.mmdb /usr/local/nginx/geoip/"
mv maxmind-city.mmdb /usr/local/nginx/geoip/

centos 7 安装 nginx maxmind GEO IP IP库相关部署的更多相关文章

  1. linux/centos下安装nginx(rpm安装和源码安装)详细步骤

    Centos下安装nginx rpm包                                                                                 ...

  2. CentOS 7安装nginx

    CentOS 7安装nginx 参考网上其他文章做的 安装Nginx 我们从nginx官方的RPM源来安装一个预构建的稳定版本的nginx包. rpm --import http://nginx.or ...

  3. CentOS 7 安装 Nginx 配置反向代理

    Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Ngi ...

  4. Centos 在线安装 nginx

    centos 在线安装 nginx 安装nginx ​ 参考文档: http://nginx.org/en/linux_packages.html 中的RHEL/CentOS章节,按照步骤安装repo ...

  5. 删:Centos 7安装Nginx 1.8

    [CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...

  6. CentOS下安装Nginx并添加nginx_upload_module

    安装前,最好能保证依赖的系统软件已经升级.    yum update CentOS上安装Nginx,如果只是简单安装,不附加其他第三方模块,一句话可以搞定:    yum install nginx ...

  7. CentOS 下 安装 nginx 执行配置命令 ./configure 报错

    CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...

  8. Linux(Centos)之安装Nginx及注意事项

    1.Nginx的简单说明 a.  Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,期初开发的目的就是为了代理电子邮件服务器室友:Igor Sysoev开发 ...

  9. Centos下安装nginx rpm包

    1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/centos/6 ...

随机推荐

  1. js替换时,空格被替换为双引号

    替换代码 str.replace(/\"/g, "'") 将双引号替换为单引号,如果字符串中,存在space(空格)时,使用以上语句将会导致空格被替换为双引号,可以使用如 ...

  2. UVA1401 (字典树加简单dp)

    #pragma GCC optimize(2) #include <bits/stdc++.h> #define ll long long using namespace std; ; ; ...

  3. 注解配置springMVC

    在随笔“springMVC项目配置文件”的基础上,进行优化,使用注解配置,控制器类得以简化: 一.注解配置springMVC 1.在HelloController类中,去除实现的Controller接 ...

  4. 4 Values whose Sum is 0 UVA 1152

    题目链接:https://vjudge.net/problem/UVA-1152 这题题意就是在四个集合内.每个集合分别里挑一个数a,b,c,d,求a+b+c+d=0有多少种选法. 暴力的话就是四重循 ...

  5. 【巨杉数据库SequoiaDB】助力金融科技升级,巨杉数据库闪耀金融展

    11月4日,以“科技助创新 开放促改革 发展惠民生”为主题的2019中国国际金融展和深圳国际金融博览会在深圳会展中心盛大开幕. 中国人民银行党委委员.副行长范一飞,深圳市人民政府副市长.党组成员艾学峰 ...

  6. 洛谷P3367 【模板】并查集 模板 找baba

    链接https://www.luogu.org/problem/P3367 #include<bits/stdc++.h> using namespace std; ; int fa[ra ...

  7. 2020牛客寒假算法基础集训营1 F-maki和tree

    链接:https://ac.nowcoder.com/acm/contest/3002/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  8. BZOJ3680 JSOI2004 平衡点 - 随机/近似算法

    迭代乱搞了下就过了…… #include <bits/stdc++.h> using namespace std; ],y[],w[]; double xm,ym,wt,k,lambda= ...

  9. PHP 实现时间戳转化为几分钟前、几小时前等格式

    //发布时间提示 function get_last_time($time) { // 当天最大时间 $todayLast = strtotime(date('Y-m-d 23:59:59')); $ ...

  10. 温故知新的经典贪心题目:今年暑假不AC?

    情景: “今年暑假不AC?” “是的.” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电 ...