• 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;
           }
        }
    }
  • 相关阅读:
    分享jstl实现分页,类似百度分页
    分享git的常用命令
    ubuntu certbot 生成免费泛域名证书
    es创建普通索引以及各种查询
    动态代理
    开闭原则
    单一原则
    单例模式
    设计模式之观察者模式
    SpringBoot集成spring-data-jpa注入Bean失败
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/14779653.html
Copyright © 2020-2023  润新知