Install GeoIP on Linux yum install nginx-module-geoip http_geoip_module usage scenarios 1. Differentiate between domestic and foreign HTTP access rules 2. Differentiate domestic cities and regions to make HTTP access rules After yum is installed, find the installed module file If nginx is installed using yun, it is usually installed in the /etc/nginx/modules/ directory Note: If nginx is not installed by yum but compiled from source code, you need to reinstall and compile nginx with this module, and then you do not need to add this module manually. Manually add modules The module is loaded at the same level as http in the header of the nginx.conf configuration file load_module "modules/ngx_http_geoip_module.so"; load_module "modules/ngx_stream_geoip_module.so"; Because GeoIP is based on the database file provided by MaxMind to read the regional information, it is necessary to download the regional file of the IP. This database is binary and cannot be opened with a text editor. The GeoIP library above is required to read it. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz #Country's regional IP wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz #City's regional IP Then unzip load_module "modules/ngx_http_geoip_module.so"; load_module "modules/ngx_stream_geoip_module.so"; ....... http{ geoip_country /etc/nginx/geoip/GeoIP.dat; #Load country IP geoip_city /etc/nginx/geoip/GeoLiteCity.dat; #Load city IP ......... server { ...... location / { #If it is not Chinese, return 403; if ($geoip_country_code != CN) { return 403; } } #Return country and city information location /myip { default_type text/plain; return 200 "$remote_addr $geoip_country_name $geoip_country_code $geoip_city"; } .... } } Then visit your IP address/myip to return the country and city information of the IP. The above method of using Nginx and GeoIP module to read the regional information of IP is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Implementation of communication between Vue and Flask
>>: Vue-pdf implements online preview of PDF files
1. Command method Run the nginx service in the cr...
Table of contents UI Design Echarts example effec...
Neo4j (one of the Nosql) is a high-performance gr...
The specific code for implementing skinning with ...
(P4) Web standards are composed of a series of sta...
Table of contents Introduction to stored procedur...
The main differences are as follows: 1. MySQL use...
Specify in CSS style file #class td /*Set the tab...
Preface: Speaking of sandboxes, our minds may ref...
If your MySQL database is installed on a centos7 ...
In the previous article, we introduced the detail...
1. HTML Overview 1.HTML: Hypertext Markup Languag...
Operating system: Window10 MySQL version: 8.0.13-...
1. Network Optimization YSlow has 23 rules. These...
1. Make sure the system has the required libaio s...