主頁 > 知識庫 > 利用Nginx_geo模塊實現(xiàn)CDN調(diào)度的配置方法

利用Nginx_geo模塊實現(xiàn)CDN調(diào)度的配置方法

熱門標(biāo)簽:網(wǎng)站建設(shè) 檢查注冊表項 美圖手機 阿里云 百度競價點擊價格的計算公式 使用U盤裝系統(tǒng) 硅谷的囚徒呼叫中心 智能手機

引入Nginx的Geo模塊

geo指令使用ngx_http_geo_module模塊提供的。默認(rèn)情況下,nginx有加載這個模塊除非人為的 --without-http_geo_module。

ngx_http_geo_module模塊可以用來創(chuàng)建變量,其值依賴于客戶端IP地址。使用方法如下:

geo指令
語法: geo [$address] $variable { ... }
默認(rèn)值: —
配置段: http

定義從指定的變量獲取客戶端的IP地址。默認(rèn)情況下,nginx從$remote_addr變量取得客戶端IP地址,但也可以從其他變量獲得。

在/usr/local/nginx/conf/nginx.conf文件內(nèi)加入以下配置
geo $geo {
    ranges;          #使用以地址段的形式定義地址,這個參數(shù)必須放在首位   
    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;
    }
}

在/usr/local/nginx/conf/文件下增加ip_geo.conf文件,用來對IP區(qū)域進行劃分,注意劃分的時候不能出現(xiàn)IP重疊現(xiàn)象,不然會出現(xiàn)”overlaps”報錯

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;

也可以以10.2.0.0/16 wuhan;這種形式來進行IP分段,這樣在nginx.conf中就不不需要使用range指令來進行定義

以上這篇利用Nginx_geo模塊實現(xiàn)CDN調(diào)度的配置方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

標(biāo)簽:賀州 山南 煙臺 湘潭 湖北 黃山 通遼 懷化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《利用Nginx_geo模塊實現(xiàn)CDN調(diào)度的配置方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266