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

发布于 2025-02-14 00:05:46 字数 565 浏览 3 评论 0原文

我正在学习使用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制作的(如上所述)

i'm in the middle of learning the basics of deployment of a simple weather web app using VM, flask, Nginx and gunicorn.
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.
according to this link:
Manual for limiting number of connections

i'm supposed to add this line in the http part:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花落人离去 2025-02-21 00:05:46

测试速率限制方案的快速工具是Siege。假设您使用的是Debian-base发行版,请使用:

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

sidenote:如果详细格式(-v -v)仍然显示您的json输出,编辑围攻配置文件(位于〜/.siege/siege.conf),然后将json_output指令设置为false;这应该解决问题。

A quick tool to test rate limit scenarios is siege. Assuming you're using Debian-base distributions, install it using:

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; this should solve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文