簡體   English   中英

限制客戶端ip地址連接,nginx

[英]limit client ip address connections, nginx

我正在學習使用 VM、flask、Nginx 和 gunicorn 部署簡單天氣 Web 應用程序的基礎知識。 我被告知將來自同一 IP 地址的連接數量限制為 5 個。意思是 - 我希望每個 ip 客戶端只能打開 5 個到我的站點的連接。 根據此鏈接:限制連接數的手冊

我應該在 http 部分添加這一行:

limit_conn_zone $binary_remote_addr zone=limitconnbyaddr:20m;

然后將此行添加到我的位置塊:

limit_conn   limitconnbyaddr  5;

然后,當然,測試nginx,重新啟動服務並檢查自己。 我的問題是:我如何檢查自己? 我想不出一種方法來測試我的行為是否好。 (順便說一句,如果我錯了 - 如果有人可以的話,我想對解決它的正確方法有一個很好的解釋)該網站是使用 python 制作的(如上面提到的燒瓶)

測試速率限制方案的快速工具是siege 假設您使用的是基於 Debian 的發行版,請使用以下命令安裝它:

sudo apt-get install siege

用法:

# -v - verbose logging
# -r 2 - run two tests
# -c 5 - open 5 concurrent connections
siege -v -r 2 -c 5 http://localhost:8080/static/img/logo.png

示例輸出(失敗的請求將顯示為紅色):

** SIEGE 4.0.7
** Preparing 5 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.84 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.96 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     1.02 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     1.02 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     1.02 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.92 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.93 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.90 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.96 secs:   84987 bytes ==> GET  /static/img/logo.png
HTTP/1.1 200     0.97 secs:   84987 bytes ==> GET  /static/img/logo.png

Transactions:                 10 hits
Availability:             100.00 %
Elapsed time:               1.99 secs
Data transferred:           0.81 MB
Response time:              0.95 secs
Transaction rate:           5.03 trans/sec
Throughput:             0.41 MB/sec
Concurrency:                4.79
Successful transactions:          10
Failed transactions:               0
Longest transaction:            1.02
Shortest transaction:           0.84

旁注:如果詳細格式( -v )仍然顯示 JSON 輸出,請編輯圍攻配置文件(位於~/.siege/siege.conf )並將json_output指令設置為false 這應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM