This blog is a work note environment: nginx version: nginx/1.14.0 centos version: centos7 The requirements are as follows: Differentiate between domestic and foreign IP addresses, and then jump to different pages. Finally, use nginx's third-party module: geoip to achieve this. I won't talk about its advantages. There are many explanations on the Internet. Let's see how to configure it. My system is configured with nignx.repo. I installed the geoip module directly using yum, without adding the module and recompiling it. yum install nginx-module-geoip Download the geoip database file cd /etc/nginx mkdir geoipdat cd geoipdat Download wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz Unzip gunzip GeoIP.dat.gz gunzip GeoLiteCity.dat.gz Configure nginx according to your needs First, load the geoip library in nginx.conf and configure it as follows: load_module "modules/ngx_http_geoip_module.so"; load_module "modules/ngx_stream_geoip_module.so"; user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } Configure the virtual host as follows: geoip_country /etc/nginx/geoipdat/GeoIP.dat; geoip_city /etc/nginx/geoipdat/GeoLiteCity.dat; server { listen 80; server_name localhost; location / { root /opt; if ($geoip_country_code = CN){ rewrite (.*) /zh$1 break; } rewrite (.*) /en$1 break; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } The opt directory is as follows [root@VM_0_15_centos opt]# tree . | └── en │ └── index.html └── en └── index.html The above is just a simple configuration. . . . The above method of using geoip for regional restriction in nginx 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:
|
<<: MySQL 5.7.16 free installation version installation and configuration method graphic tutorial
>>: Solution to the paging error problem of MySQL one-to-many association query
Reference: MySQL character set summary utf8mb4 ha...
iOS 1. URL scheme This solution is basically for ...
Effect picture: 1. Import files <script src=&q...
Introduction: AD is the abbreviation of Active Di...
When using the <html:reset> tag, sometimes w...
As the title says: The height is known, the width...
GTID-based replication Introduction GTID-based re...
This article shares with you a practical web navi...
Many friends found that the box model is a square...
Table of contents 1. Parent components and child ...
Recently, the company has put forward a requireme...
1. Download MySQL Workbench Workbench is a graphi...
Table of contents Write docker-compose.yml Run do...
1. display:box; Setting this property on an eleme...
Table of contents 1. Resource download 2. Unzip t...