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
1. What are CSS methodologies? CSS methodologies ...
If you think the system is slow and want to chang...
Table of contents 1. User created script 2. Word ...
Table of contents 1. Introduction 2. Output Infor...
This article shares the specific code of JavaScri...
Generally speaking, after the container is starte...
Drop-shadow and box-shadow are both CSS propertie...
Table of contents MySQL query tree structure 1. A...
Table of contents 1. Solution 2. Let the browser ...
Table of contents posgresql backup/restore mysql ...
Script requirements: Back up the MySQL database e...
Import the data exported from the Oracle database...
Since Uniapp does not have DingTalk authorization...
System version [root@ ~]# cat /etc/redhat-release...
frame: Style=”border-style:solid;border-width:5px;...