Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using Nginx_geo module to realize CDN scheduling

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Using Nginx_geo module to realize CDN scheduling? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Geo module introduced into Nginx

The geo instruction is provided by the ngx_http_geo_module module. By default, nginx has to load this module unless artificially-- without-http_geo_module.

The ngx_http_geo_module module can be used to create variables whose values depend on the client IP address. The method of use is as follows:

Geo instruction syntax: geo [$address] $variable {...} default value:-configuration segment: http

Defines to get the IP address of the client 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; # to define the address in the form of an address field, this parameter must be placed in the first default dn; include ip_geo.conf;} upstream wuhan.server {server 192.168.155.98geo 8081;} upstream shanghai.server {server 192.168.155.988082 } upstream shenzhen.server {server 192.168.155.98 jiaoyu.media.cloudp.cc; root html; index index.html index.htm; location 8083;} upstream dn.server {server 192.168.155.98 upstream dn.server 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 an ip_geo.conf file under the / usr/local/nginx/conf/ file to divide the IP area. Note that there can be no IP overlap during the division, otherwise there will be a "overlaps" error

Vim / usr/local/nginx/conf/ip_geo.conf192.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 This is the answer to the problem of using Nginx_geo module to achieve CDN scheduling. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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: 0

*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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report