2

Nginx如何对单个url的访问频率进行限制

 2 years ago
source link: https://www.huhexian.com/23568.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Nginx如何对单个url的访问频率进行限制

2022-01-1713:05:24评论379字

近期有不法人员针对公司的登录地址进行非法暴力破解,所以本人加上了登录页面的单个ip的频率限制写法如下!

Nginx如何对单个url的访问频率进行限制

http 模块中加入:

  1. #定义一个名为allips的limit_req_zone用来存储session,大小是10M内存,
  2. #1M能存储16000个状态,rete的值必须为整数,
  3. #限制两秒钟一个请求,设置成30r/m
  4. ......
  5. limit_req_zone $binary_remote_addr zone=g6k:10m rate=30r/m;
  6. ......

在 server 模块中匹配需要限制的 url:

  1. #限制URL /login 的访问频率
  2. location /login {
  3. limit_req zone=g6k burst=5 nodelay;

添加好后记得使用一下命令检查配置文件和重载配置

  1. nginx -t
  2. nginx -s reload

基本就实现了对单个 url 的访问频率控制!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK