nginx 实现带burst的并发连接数控制

先安装openresty,直接去官网下载https://openresty.org

lua插件https://github.com/openresty/lua-resty-limit-traffic/blob/master/lib/resty/limit/conn.md

conf/conf.d/xxx.com.conf

lua_shared_dict limit_conn_store 8m;
server {
    listen 8080;
    server_name xxx.com;
    root /srv/www/xxx/public;
    include php;
}

conf/php

if (!-e $request_filename) {
    rewrite  ^/(.*)$  /index.php/$1 last;
}
location ~* \.php($|/) {
        access_by_lua_file lua/conn_access.lua;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param SERVER_NAME       $server_name;
        fastcgi_param PATH_INFO         $fastcgi_script_name;
        log_by_lua_file lua/conn_log.lua;
}

继续阅读