In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces nginx how to use geoip to do regional restrictions, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The GeoIP filter adds information about the geographic location of the IP address based on data from the Maxmind GeoLite2 database.
Through IP to distinguish between domestic and foreign, so as to jump to different pages, and finally use nginx's third-party module:geoip to achieve, not to mention its advantages, there are many explanations online, let's see how to configure (recommended learning: nginx use)
My system is configured with nignx.repo, I directly use yum to install the geoip module, not by adding module reprogramming
Yum install nginx-module-geoip
Download the database file for geoip
Download cd / etc/nginxmkdir geoipdatcd geoipdat to download wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gzwget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz and extract gunzip GeoIP.dat.gzgunzip GeoLiteCity.dat.gz
Configure nginx according to demand
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 include errorists 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 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 └── zh └── index.html Thank you for reading this article carefully. I hope the article "how to use geoip to restrict areas in nginx" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 289
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.