ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
###http_geoip_module模块 需要更换下nginx的yum源 ```` vim /etc/yum.repos.d/nginx.repo ```` ```` ###配置nginx [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 ```` ###yum安装geoip ```` yum install nginx-module-geoip yum -y install GeoIP GeoIP-devel GeoIP-data ```` ```` ###安装nginx yum install nginx -y ```` ####下载geoip dat数据文件 ```` 地址如下 国家文件: wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz 城市文件:wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz ```` 解压相应文件 ```` gunzip GeoIP.dat.gz gunzip GeoLiteCity.dat.gz ```` ###把解压的数据放到/etc/nginx/下 nginx编译版本下载 到官网下载相应的版本解压即可 在现有的版本查看一下版本以及编译的模块 nginx -V ```` [root@localhost ~]# nginx -V nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' ```` ###添加模块进行编译 --with-http_geoip_module ###安装依赖库 ```` yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel cURL cURL-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel wget gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison pcre-devel epel-release-6-8.noarch ntp gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison pcre-devel pcre-devel ntp gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison sendmail vim gperftools-devel perl-ExtUtils-Embed libxslt-devel gd gd-devel ```` ####安装开发工具 补救 落下文件 ```` yum groupinstall "Development Libraries" "Development Tools" ```` 具体看自己编译的nginx ```` ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_geoip_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' ```` ###编译完成后make一下即可注意千万不要make install否则会覆盖歇菜的 编译好后覆盖原来的nginx 文件同时给上权限 ###nginx配置修改 vi /etc/nginx/nginx.conf 在http{}之间添加配置来读取数据 ```` http { geoip_country /etc/nginx/GeoIP.dat; geoip_city /etc/nginx/GeoLiteCity.dat; include /etc/nginx/mime.types; ##必须在include上面配置 ```` server配置 ```` server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; 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"; } ```` ###实例2 ```` server { … if (geoip_country_code = CN) { rewrite ^(.*)geoip_country_code = CN) { rewrite ^(.*) http://baidu.com; } if (geoip_country_code != CN) { rewrite ^(.*)geoip_country_code != CN) { rewrite ^(.*) http://qq.com; } … } ````