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 As you know, Linux supports many file sys...
When it comes to remote desktop connection to Lin...
The display effects on IE, Fir...
Directly to the configuration file server { liste...
Ubuntu's own source is from China, so the dow...
1 Cause After the project migrated the database a...
Table of contents Install Tomcat with Docker Use ...
TRUNCATE TABLE Deletes all rows in a table withou...
IE8 new feature Web Slices (Web Slices) Microsoft...
Table of contents What is Proxy Mode? Introducing...
First, let’s take a look at the picture: Today we...
Flexible layout (Flexbox) is becoming increasingl...
For many people who are new to HTML, table <ta...
Overview For small and medium-sized projects, joi...
This article shares the specific code of JS to ac...