简体   繁体   English

限制 Nginx 最大并发连接数

[英]Limit Nginx max concurrent connections

I am looking for a way to limit the number of maximum concurrent connections to 1. I do not want a connection limit per IP, I already know this is supported.我正在寻找一种将最大并发连接数限制为 1 的方法。我不想要每个 IP 的连接限制,我已经知道这是支持的。

As far as I can see, max_conns would be exactly what I'm looking for, but unfortunately it's not available in the free version:据我所知, max_conns正是我正在寻找的,但不幸的是它在免费版本中不可用:

Additionally, the following parameters are available as part of our commercial subscription此外,以下参数可作为我们商业订阅的一部分

Limiting worker_connections is not an option, as the minimum it wants is 4, and it affects more than the incoming requests.限制worker_connections不是一个选项,因为它需要的最小值是 4,并且它影响的不仅仅是传入的请求。

My conf:我的配置:

server {
listen       80;
server_name  localhost;

location / {
rewrite_by_lua '
     [some lua code]
';

    proxy_pass http://127.0.0.1:8080;
 }
}

Literally moments after I posted this question, I stumbled uponthis while googling for how to whitelist IPs from a file in Nginx!在我发布这个问题后不久,我在谷歌搜索如何将 Nginx 中的文件中的 IP 列入白名单时偶然发现了这一点 Kind of funny considering I spent the last 2 hours googling for specific terms about rate limiting;考虑到我在过去的 2 个小时里用谷歌搜索有关速率限制的特定术语,这有点有趣; talk about relevance, heh..谈相关性,呵呵..

limit_conn_zone $server_name zone=servers:1m;
limit_conn servers 1;

This in the http { block seems to do the trick.这在http {块中似乎可以解决问题。

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

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