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
Let me first talk about the implementation steps:...
Table of contents Preface optimization SSR Import...
What is my.ini? my.ini is the configuration file ...
describe This article introduces a method to impl...
This post focuses on a super secret Flutter proje...
Execute the command: docker run --name centos8 -d...
Table of contents MySQL multi-version concurrency...
This article describes MySQL multi-table query wi...
Table of contents EffectList Collection EffectLis...
This article mainly introduces the relevant solut...
Engineering Structure The project is divided into...
Table of contents 1. Use the uuid function to gen...
This script can satisfy the operations of startin...
In-depth understanding of this in Js JavaScript s...
Let’s take the translation program as an example....