Introducing the Geo module of Nginx The geo directive is provided by the ngx_http_geo_module module. By default, nginx loads this module unless --without-http_geo_module is specified. The ngx_http_geo_module module can be used to create variables whose values depend on the client IP address. Here’s how to use it: Syntax of geo directive: geo [$address] $variable { ... } default value: - Configuration section: http Defines how to get the client's IP address from the specified variable. By default, nginx gets the client IP address from the $remote_addr variable, but it can also be obtained from other variables. Add the following configuration to the /usr/local/nginx/conf/nginx.conf file geo $geo { ranges; #Use the address in the form of address segments, this parameter must be placed first default dn; include ip_geo.conf; } upstream wuhan.server { server 192.168.155.98:8081; } upstream shanghai.server { server 192.168.155.98:8082; } upstream shenzhen.server { server 192.168.155.98:8083; } upstream dn.server { server 192.168.155.98:8084; } server { listen 80; server_name 192.168.155.98 jiaoyu.media.cloudp.cc; root html; index index.html index.htm; location ~* \.xml$ { root /data/video; } location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://$geo.server$request_uri; } } server { listen 8081; server_name 192.168.155.98; location / { rewrite ^ $scheme://192.168.155.106$request_uri? permanent; } } server { listen 8082; server_name 192.168.155.98; location / { rewrite ^ $scheme://192.168.155.107$request_uri? permanent; } } server { listen 8083; server_name 192.168.155.98; location / { rewrite ^ $scheme://192.168.155.109$request_uri? permanent; } } server { listen 8084; server_name 192.168.155.98; location / { rewrite ^ $scheme://jiaoyu.dn.cloudp.cc$request_uri? permanent; } } Add the ip_geo.conf file under /usr/local/nginx/conf/ to divide the IP area. Note that there should be no IP overlap when dividing, otherwise an "overlaps" error will be reported. vim /usr/local/nginx/conf/ip_geo.conf 192.168.128.6-192.168.128.10 wuhan; 192.168.128.11-192.168.128.15 shanghai; 192.168.128.16-192.168.128.20 shenzhen; You can also segment IP addresses in the form of 10.2.0.0/16 wuhan; so you don't need to use the range directive to define it in nginx.conf. The above configuration method of using Nginx_geo module to implement CDN scheduling 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:
|
<<: Summary of the minesweeping project implemented in JS
>>: MySQL 5.7.23 installation and configuration graphic tutorial
Preface The keywords of MySQL and Oracle are not ...
Use the rpm installation package to install mysql...
Recently, an online security scan found a vulnera...
The main text page of TW used to have a width of 8...
Table of contents 【Code background】 【Code Impleme...
1. Remove MySQL a. sudo apt-get autoremove --purg...
This article example shares the specific code of ...
This article uses examples to illustrate the usag...
Preface Here are the steps to install and configu...
<p><b>This is bold font</b></...
npm installation tutorial: 1. Download the Node.j...
The process of installing MySQL database and conf...
All previous projects were deployed in the Window...
Step 1: Configure environment variables (my decom...
This article example shares the specific code for...