»» » 寶塔麵板NGINX的GeoIP2模塊配置

寶塔麵板NGINX的GeoIP2模塊配置 -

來源 : 2019-03-22技術文檔伺服器配置GeoIP2  0

本文簡單扼要介紹NGINX配置最新的GEOIP2模塊(以寶塔麵板為例,同樣適合各種其他麵板)

此處忽略寶塔安裝過程以及NGINX安裝過程.

首先下載GeoLite2 mmdb(可在SSH直接粘帖本代碼,下載解壓到/usr/share/GeoIP/):

cd /usr/share/GeoIP/;wget mac://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz;gunzip GeoLite2-City.mmdb.gz;wget mac://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz;gunzip GeoLite2-Country.mmdb.gz

安裝libmaxminddb

cd /usr/local/src

git clone --recursive https://github.com/maxmind/libmaxminddb

cd libmaxminddb

./bootstrap

./configure

make

make install

sh -c "echo /usr/local/lib  >> /etc/ld.so.conf.d/local.conf"

ldconfig 

安裝ngx_http_geoip2_module

寶塔的NGINX模塊目錄

/www/server/nginx/src

命令步驟:

cd /www/server/nginx/src

git clone --recursive https://github.com/leev/ngx_http_geoip2_module

在加載模塊前,有必要使用 nginx -V 查看一下目前nginx模塊情況

接下去的命令步驟(加粗部分是現在安裝的GEOIP2模塊):

 ./configure --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --add-module=/www/server/nginx/src/nginx-http-concat --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-pcre=pcre-8.40 --with-ld-opt=-ljemalloc--add-module=/www/server/nginx/src/ngx_http_geoip2_module 

make

make install 


ngx_http_geoip2_module 模塊配置(寶塔Nginx配置修改,其他則直接在Nginx.conf增加)

http{ #http區域

...

geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {

    #auto_reload 5m;

    #$geoip2_metadata_country_build metadata build_epoch;

    #$geoip2_data_country_code default=US source=$variable_with_ip country iso_code;

    $geoip2_data_country_code default=US country iso_code;

    $geoip2_data_country_name country names en;

}


geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {

    $geoip2_data_city_name default=London city names en;

}

...

文章到此結束,後續其他問題會繼續跟進

本文章翻譯自:

www.nginxer.com/records/how-to-install-the-geoip2-module-for-nginx-on-the-baota-panel/


本站文章除特別說明外,全部來自於本站用戶投稿或者網站原創,轉載請務必注明出處.
如文章部分內容出錯,請【報告】,感謝.

 
02019-03-22 11:58:10
提示!需要先登錄 才可以評論. 還沒有賬戶? 您可以馬上 創建免費賬戶