NG版本:Tengine version: Tengine/2.2.1 (nginx/1.8.1) ngx_http_limit_conn_module和ngx_http_limit_req_module两个模块是有的,具体见下方./nginx -V信息
目的是限制单个IP的访问次数 配置语句: 【http中的配置】 limit_conn_zone $binary_remote_addr zone=perip:10m; limit_req_zone $binary_remote_addr $uri zone=one:3m rate=1r/s; (或者limit_req_zone $binary_remote_addr zone=one:3m rate=1r/s;) 【location中的配置】 limit_conn perip 1; limit_req zone=one;
【测试结果的日志】同一秒内都是成功的,没有达到效果。 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58329|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.219|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.219 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58345|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.278|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.278 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58344|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.251|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.251 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58332|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.372|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.372 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58331|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.372|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.372 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58330|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.372|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.372 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58340|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.543|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.543 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58363|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.329|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.329 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58367|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.587|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.587 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58368|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.550|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.550 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58369|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.504|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.504 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58338|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.482|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.482 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58360|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.434|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.434 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58336|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.482|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.482 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58359|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.434|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.434 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58341|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.482|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.482 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58370|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.257|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.257 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58337|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.482|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.482 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58366|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.304|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.304 /vcweixin4/cdyt/seckill/test?company=cdyt&a=222|www.test.cn|www.test.cn|192.168.2.254|58334|-|29/Sep/2018:09:15:42 +0800|GET /vcweixin4/cdyt/seckill/t est?company=cdyt&a=222 HTTP/1.1|200|2.482|1517|-|Apache-HttpClient/4.2.6 (java 1.5)|-|www.test.cn|-|-|192.168.2.186:8889|2.482
【nginx -V信息】 $ ./nginx -V Tengine version: Tengine/2.2.1 (nginx/1.8.1) built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) TLS SNI support enabled configure arguments: --prefix=/home/culngx/culp/ngx --with-pcre=/home/culngx/culp/pcre-8.41/ --with-http_ssl_module --with-http_sub_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_lua_module --with-luajit-inc=/home/culngx/culp/luajit/include/luajit-2.0/ --with-luajit-lib=/home/culngx/culp/luajit/lib/ --with-ld-opt=-Wl,-rpath,/home/culngx/culp/luajit/lib/:/home/culngx/culp/pcre/lib/ --with-pcre-jit nginx: loaded modules: nginx: ngx_core_module (static) nginx: ngx_errlog_module (static) nginx: ngx_conf_module (static) nginx: ngx_dso_module (static) nginx: ngx_events_module (static) nginx: ngx_event_core_module (static) nginx: ngx_epoll_module (static) nginx: ngx_procs_module (static) nginx: ngx_proc_core_module (static) nginx: ngx_openssl_module (static) nginx: ngx_regex_module (static) nginx: ngx_http_module (static) nginx: ngx_http_core_module (static) nginx: ngx_http_log_module (static) nginx: ngx_http_upstream_module (static) nginx: ngx_http_static_module (static) nginx: ngx_http_gzip_static_module (static) nginx: ngx_http_autoindex_module (static) nginx: ngx_http_index_module (static) nginx: ngx_http_auth_request_module (static) nginx: ngx_http_auth_basic_module (static) nginx: ngx_http_access_module (static) nginx: ngx_http_limit_conn_module (static) nginx: ngx_http_limit_req_module (static) nginx: ngx_http_realip_module (static) nginx: ngx_http_geo_module (static) nginx: ngx_http_map_module (static) nginx: ngx_http_split_clients_module (static) nginx: ngx_http_referer_module (static) nginx: ngx_http_rewrite_module (static) nginx: ngx_http_ssl_module (static) nginx: ngx_http_proxy_module (static) nginx: ngx_http_fastcgi_module (static) nginx: ngx_http_uwsgi_module (static) nginx: ngx_http_scgi_module (static) nginx: ngx_http_memcached_module (static) nginx: ngx_http_empty_gif_module (static) nginx: ngx_http_browser_module (static) nginx: ngx_http_user_agent_module (static) nginx: ngx_http_upstream_hash_module (static) nginx: ngx_http_upstream_ip_hash_module (static) nginx: ngx_http_upstream_consistent_hash_module (static) nginx: ngx_http_upstream_check_module (static) nginx: ngx_http_upstream_least_conn_module (static) nginx: ngx_http_upstream_keepalive_module (static) nginx: ngx_http_upstream_dynamic_module (static) nginx: ngx_http_stub_status_module (static) nginx: ngx_http_write_filter_module (static) nginx: ngx_http_header_filter_module (static) nginx: ngx_http_chunked_filter_module (static) nginx: ngx_http_range_header_filter_module (static) nginx: ngx_http_gzip_filter_module (static) nginx: ngx_http_postpone_filter_module (static) nginx: ngx_http_ssi_filter_module (static) nginx: ngx_http_charset_filter_module (static) nginx: ngx_http_sub_filter_module (static) nginx: ngx_http_userid_filter_module (static) nginx: ngx_http_footer_filter_module (static) nginx: ngx_http_trim_filter_module (static) nginx: ngx_http_headers_filter_module (static) nginx: ngx_http_upstream_session_sticky_module (static) nginx: ngx_http_reqstat_module (static) nginx: ngx_http_lua_module (static) nginx: ngx_http_copy_filter_module (static) nginx: ngx_http_range_body_filter_module (static) nginx: ngx_http_not_modified_filter_module (static)