简体   繁体   English

限制客户端ip地址连接,nginx

[英]limit client ip address connections, nginx

i'm in the middle of learning the basics of deployment of a simple weather web app using VM, flask, Nginx and gunicorn.我正在学习使用 VM、flask、Nginx 和 gunicorn 部署简单天气 Web 应用程序的基础知识。 i've been told to limit the amount of connections from the same ip address to 5. meaning - i would like that each ip client could open only 5 connections to my site.我被告知将来自同一 IP 地址的连接数量限制为 5 个。意思是 - 我希望每个 ip 客户端只能打开 5 个到我的站点的连接。 according to this link: Manual for limiting number of connections根据此链接:限制连接数的手册

i'm supposed to add this line in the http part:我应该在 http 部分添加这一行:

limit_conn_zone $binary_remote_addr zone=limitconnbyaddr:20m;

then add this line to my location block:然后将此行添加到我的位置块:

limit_conn   limitconnbyaddr  5;

and afterwards, of course, test nginx, restart the service and check myself.然后,当然,测试nginx,重新启动服务并检查自己。 my question is: how can i check myself?我的问题是:我如何检查自己? i can't figure out a way to test if my actions were good or not.我想不出一种方法来测试我的行为是否好。 (BTW, if i'm wrong - i'd like to have a good explanation to the correct way to solve it, if anyone can) the website is made using python (as flask mentioned above) (顺便说一句,如果我错了 - 如果有人可以的话,我想对解决它的正确方法有一个很好的解释)该网站是使用 python 制作的(如上面提到的烧瓶)

A quick tool to test rate limit scenarios is siege .测试速率限制方案的快速工具是siege Assuming you're using Debian-base distributions, install it using:假设您使用的是基于 Debian 的发行版,请使用以下命令安装它:

sudo apt-get install siege

Usage:用法:

# -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

Sample output (the failed requests will appear in red):示例输出(失败的请求将显示为红色):

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

Sidenote: if the verbose format ( -v ) still shows you a JSON output, edit the siege configuration file (located at ~/.siege/siege.conf ) and set the json_output directive to false ;旁注:如果详细格式( -v )仍然显示 JSON 输出,请编辑围攻配置文件(位于~/.siege/siege.conf )并将json_output指令设置为false this should solve the issue.这应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM