[Nginx配置系列] 基於Nginx Geo與 Nginx Map模組進行Nginx白名單配置

來源:互聯網
上載者:User

標籤:

一、簡介

      在通常情況下,使用 nginx 基於 ip 限制訪問請求頻率等限制內容,我們會需要對特定ip進行限制排除操作,因此本文引入了基於nginx geo 與 nginx map 進行此類情景相關配置;

      在沒有人為操作刪除的情況下(without-http_geo_module),nginx預設模組中已經載入了ngx-http-geo-module相關內容;

       ngx-http-geo-module可以用來建立變數,變數值依賴於用戶端 ip 地址;

       ngx-http-map-module可以基於其他變數及變數值進行變數建立,其允許分類,或者映射多個變數到不同值並儲存在一個變數中;

      ngx-http-map-module相關內容同樣在預設nginx中已存在,除非由人為移除( --without-http_map_module)

二、相關指令格式

Nginx geo 格式說明

Syntax ( 文法格式 ): geo [$address] $variable { ... }Default ( 預設 ): -Content ( 配置段位 ): http


Nginx map 格式說明

Syntax ( 文法格式 ): map String $variable { ... }Default ( 預設 ):-Content ( 配置段位 ): http


三、白名單配置樣本

   

http{    #定義白名單ip列表變數    geo $whiteiplist {           default : 1 ;          #myself           127.0.0.1/32 0;         #remote ip           64.223.160.0/19 0;     }          #使用map指令映射將白名單列表中用戶端請求ip為空白串     map $whiteiplist $limit{        1 $binary_remote_addr ;        0 ""     }          #配置要求節流內容     limit_req_zone $limit zone=foo:1m rate=10r/m;     limit_req zone=foo burst=5;     }

        白名單配置可用於對合作客戶,搜尋引擎等請求過濾限制

  

四、參考資料

參考官方文檔: 

 ngx-http-geo-module

 ngx-http-map-module

[Nginx配置系列] 基於Nginx Geo與 Nginx Map模組進行Nginx白名單配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.