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. GYCTFblacklist[堆叠注入 ]

    考点:堆叠注入 handler语句代替select查询 类似于强网杯随便注 不同是过滤了alter,set等函数,不能通过改变列命或着sql预处理查询表内数据 可以使用handler语句代替selec ...

  2. IDAE打包WEB项目 WAR Eclipse转IDEA项目

    接下来这里只说WEB项目打包,相信大多数都是用的WEB项目吧,关于打包WAR,真的很头痛,网上说的试了好好次都不行. 后来懂了之后,真的很简单好么,分享给大家   不要多走弯路了. 注意:   如果你 ...

  3. vue中jquery详情

    jQuery基本语法 $(selector).action() 基本选择器:$("#id") 标签选择器:$("tagName") class选择器:$(&qu ...

  4. centos8 常用软件

    防火墙 GUI版 https://blog.csdn.net/qq_36492368/article/details/80432259 dnf install -y firewall-config d ...

  5. H5 使用input标签上传图片给后台

    html代码: <div class="hpk-showimg"> <!-- 营业执照 --> <div class="idcardup&q ...

  6. vue里使用elementUI里的下拉树表格,如何定义个性化的子表格?

    最近项目写到一个业务,首先需要展示各类分组的基本信息,然后需要点击每个分组展示该分组下子的所有具体信息 一开始我是打算用tab来展示就是首先父分组的名称就是各个不同的tab按钮,然后点击按钮再展示不同 ...

  7. redis分布式锁在springboot中的实现

    理论知识   redis分布式锁的实现方案请参考文章 如何优雅地用redis实现分布式锁 本案例简介   以秒杀活动为例子,在多线程高并发的情况下需要保证秒杀业务的线程安全性,确保秒杀记录与所扣库存数 ...

  8. SpringBoot学习- 3、整合MyBatis

    SpringBoot学习足迹 1.下载安装一个Mysql数据库及管理工具,同类工具很多,随便找一个都可以,我在windows下做测试项目习惯使用的是haosql 它内部集成了MySql-Front管理 ...

  9. 关于setTimeout的妙用

    定义 在指定的延迟时间之后调用一个函数或执行一个代码片段 这个是setTimeout最主要的功能,但也是很坑的地方,首先javascript其实是运行在单线程的环境下,意味者定时器会在未来的某个时间支 ...

  10. 四、CentOS 7安装Oracle JDK

    CentOS 7安装Oracle JDK,查看Linux是否自带的JDK,如有openJDK,则卸载  CentOS7.1 JDK安装 1.卸载自带OPENJDK    用 java -version ...