limit:限制,rep:请求
  1. 启动请求限制频率
  2. ngx_http_limit_req_module
  3. #测试命令
  4. ab -n 100 -c 10 http://a.com/
  5. -c 一次产生的请求个数。默认是一次一个。
  6. -n #发起多少次请求,在测试会话中所执行的请求个数。默认时,仅执行一个请求。
  7. #详解
  8. 限制请求 二进制地址 限制策略的名称 占用10M空间 允许每秒1次请求
  9. limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s;
  10. 应用 限制策略名称
  11. limit_req zone=req_zone;
  12. #案列
  13. vim /etc/nginx/nginx.conf
  14. http {
  15. limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s;
  16. }
  17. vim
  18. location / {
  19. limit_req zone=req_zone; #使用
  20. root /usr/share/nginx/html;
  21. index index.html index.htm;
  22. }
  23. #限制连接次数
  24. ngx_http_limit_conn_module