1. 程式人生 > >控制 Nginx 並發連接數

控制 Nginx 並發連接數

sendfile htm types conf 虛擬 name timeout ... index

一、限制單個 IP 的並發連接數

[[email protected] ~]# cat /usr/local/nginx/conf/nginx.conf
.... 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 } } }

二、限制虛擬主機總連接數

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

控制 Nginx 並發連接數