How to configure CDN scheduling using Nginx_geo module

How to configure CDN scheduling using Nginx_geo module

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:
  • Detailed explanation of the geo module in Nginx and examples of using it to configure load balancing
  • Nginx geoip module to achieve regional load balancing
  • Detailed explanation of the configuration and use of the map module in the Nginx server

<<:  Summary of the minesweeping project implemented in JS

>>:  MySQL 5.7.23 installation and configuration graphic tutorial

Recommend

How to view the type of mounted file system in Linux

Preface As you know, Linux supports many file sys...

Remote Desktop Connection between Windows and Linux

When it comes to remote desktop connection to Lin...

Nginx prohibits direct access via IP and redirects to a custom 500 page

Directly to the configuration file server { liste...

Example of how to change the domestic source in Ubuntu 18.04

Ubuntu's own source is from China, so the dow...

Detailed steps for installing Tomcat, MySQL and Redis with Docker

Table of contents Install Tomcat with Docker Use ...

Explanation of Truncate Table usage

TRUNCATE TABLE Deletes all rows in a table withou...

What are Web Slices?

IE8 new feature Web Slices (Web Slices) Microsoft...

Detailed explanation of the principle of js Proxy

Table of contents What is Proxy Mode? Introducing...

Example code for Html layered box-shadow effect

First, let’s take a look at the picture: Today we...

The simplest form implementation of Flexbox layout

Flexible layout (Flexbox) is becoming increasingl...

Tips on setting HTML table borders

For many people who are new to HTML, table <ta...

MySQL joint table query basic operation left-join common pitfalls

Overview For small and medium-sized projects, joi...

JS version of the picture magnifying glass effect

This article shares the specific code of JS to ac...