控制 Nginx 併發連接數

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

複製代碼

[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
....
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;   
    server {
        listen       80;
        server_name  www.abc.com;
        location / {
            root   html/www;
            index  index.html index.htm;            
        }
    }
}

複製代碼

 

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

複製代碼

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

複製代碼


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章