zoukankan      html  css  js  c++  java
  • nginx 开启连接数限制

    首先查看,配置文件,可以看出,这两个模块,已经内置 ,不需要另外安装。

    ./configure --help | grep http_limit_

      --without-http_limit_conn_module   disable ngx_http_limit_conn_module

      --without-http_limit_req_module    disable ngx_http_limit_req_module

    在conf文件中配置

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
    upstream report{
    server 127.0.0.1:8080;
    
    check interval=3000 rise=2 fall=5 timeout=2000 type=http;
    check_http_expect_alive http_2xx http_3xx;
    }
    #限制请求
    limit_req_zone $binary_remote_addr  zone=one:20m rate=5r/s;
    ##按ip配置一个连接 zone
    limit_conn_zone $binary_remote_addr zone=perip_conn:10m;
    ##按server配置一个连接 zone
    limit_conn_zone $server_name zone=perserver_conn:100m;
    
    
    
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
     #请求限流排队通过 burst默认是0
    limit_req zone=one burst=5;
     #连接数限制,每个IP并发请求为2
    limit_conn perip_conn 2;
    #服务所限制的连接数(即限制了该server并发连接数量)
    limit_conn perserver_conn 1000;
    #连接限速
    limit_rate 100k;
    proxy_pass      http://report;
    #
            }
    
           
          location /status {
          check_status;
           }
        }
    }
  • 相关阅读:
    祈澈菇凉的高端知识资源分享星球开通
    使用mpvue开发小程序教程(五)
    使用mpvue开发小程序教程(四)
    使用mpvue开发小程序教程(三)
    使用mpvue开发小程序教程(二)
    使用mpvue开发小程序教程(一)
    手把手教你用vue-cli构建一个简单的路由应用
    wangEditor
    从列表中或数组中随机抽取固定数量的元素组成新的数组或列表
    js学习总结----核心解读
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/14779653.html
Copyright © 2011-2022 走看看