编程技术分享平台

网站首页 > 技术教程 正文

nginx——控制 Nginx 并发连接数(nginx 并发限流)

xnh888 2024-10-13 10:20:21 技术教程 16 ℃ 0 评论

1. 限制单个 IP 的并发连接数

....

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

limit_conn_zone $binary_remote_addr zone=addr:10m; # 用于设置共享内存区域,addr 是共享内存区域的名称,10m 表示共享内存区域的大小

server {

listen 80;

server_name www.abc.com;

location / {

root html/www;

index index.html index.htm;

limit_conn addr 1; # 限制单个IP的并发连接数为1

}

}

}

2. 限制虚拟主机总连接数

....

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

limit_conn_zone $server_name zone=perserver:10m;

server {

listen 80;

server_name www.abc.com;

location / {

root html/www;

index index.html index.htm;

limit_conn perserver 2; # 设置虚拟主机连接数为2

}

}

}

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表