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

Detailed explanation of keywords and reserved words in MySQL 5.7

Preface The keywords of MySQL and Oracle are not ...

Install mysql offline using rpm under centos 6.4

Use the rpm installation package to install mysql...

Notes on upgrading to mysql-connector-java8.0.27

Recently, an online security scan found a vulnera...

When to use table and when to use CSS (experience sharing)

The main text page of TW used to have a width of 8...

Element sample code to implement dynamic table

Table of contents 【Code background】 【Code Impleme...

JS+CSS to realize dynamic clock

This article example shares the specific code of ...

Example analysis of mysql shared lock and exclusive lock usage

This article uses examples to illustrate the usag...

Detailed steps for installing and configuring MySQL 8.0 on CentOS

Preface Here are the steps to install and configu...

Detailed explanation of node.js installation and HbuilderX configuration

npm installation tutorial: 1. Download the Node.j...

MySQL 8.0.11 MacOS 10.13 installation and configuration method graphic tutorial

The process of installing MySQL database and conf...

Tutorial on installing MySQL 5.6 using RPM in CentOS

All previous projects were deployed in the Window...

JavaScript to achieve uniform animation effect

This article example shares the specific code for...