nginx限制同一个ip访问频率

nginx.conf配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #定义一个名为zone的limit_req_zone,大小是10M内存,
    #rate (次数)r/(m:每两秒,s:每秒)
    # 这里限制的每秒为30个请求,超过nginx会抛(503 Service Temporarily Unavailable)
   limit_req_zone $binary_remote_addr zone=one:10m rate=30r/s; 

 server{
  listen       80; # 监听端口
  server_name  test1_http.com;#域名
  location / {
   
        #漏桶数burst为5  (30+5) 
        limit_req zone=allips burst=5 nodelay;
     
       proxy_pass http://test2_http.com; # 需要代理的域名
       proxy_set_header    X-Real-IP        $remote_addr; # 请求头中设置 用户真实ip
       proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
       proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;
     
   }
 }
}

你可能感兴趣的:(nginx限制同一个ip访问频率)