爱上小男人

Nginx limit_req 限流:几行配置挡住大部分CC攻击_我的网站

真女神转生

A |     (ECNS) -- For Vitaly, a Chinese language teacher at Russia’s Higher School of Economics, textbooks tell only part of the story.    Born in 2002, Vitaly has found a creative way to engage his students with the language: AI-generated short dramas and Chinese pop culture.        “I watch Chinese AI short dramas to improve my own language skills, and I bring that same creative approach into the classroom,” Vitaly said.    By drawing on the fast-paced and engaging format of short videos, he helps students understand grammar and vocabulary in a more accessible and memorable way.    This summer, Vitaly led more than 80 Russian translation students to Changchun, Jilin Province, for a month-long study program at Jilin International Studies University.    Beyond the classroom, he encourages students to immerse themselves in contemporary Chinese youth culture, from collecting popular blind boxes to sampling local food at night markets.    Fluent in Chinese and familiar with everything from idioms and classical prose to the latest internet slang and memes, Vitaly believes that experiencing China firsthand is one of the best ways to understand the country.     By combining classroom learning with digital trends and everyday cultural experiences, he hopes to inspire a new generation of translators and help strengthen cultural exchanges between China and Russia.    (By Helen Mo, intern Lin Qiaochu)                    。    

     一键部署OpenClaw        服务器CPU莫名飙高,带宽跑满,看日志全是同一个IP一秒打来几十个请求——这不是业务火了,是被CC了。扛CC的第一道闸门不在代码里,在Nginx的限流模块里,配置成本几乎为零。    limit_req的原理是漏桶:你设定一个速率,超速的请求直接返回503或延迟排队。先用limit_req_zone定义一个计数区,再在location里挂上limit_req,两步完事。    

# nginx.conf 的 http 块里定义限流区
    # 以客户端IP为key,10MB内存可存约16万个IP状态    # rate=10r/s 表示平均每秒最多放行10个请求    limit_req_zone $binary_remote_addr zone=req_per_ip:10m rate=10r/s;    # server 或 location 块里应用    server {    location / {    limit_req zone=req_per_ip burst=20 nodelay;    proxy_pass http://127.0.0.1:8080;    }    }    burst=20是缓冲队列长度,配合nodelay表示突发20个请求立即处理、不排队,超出就直接拒。想对登录、搜索这类昂贵接口管得更严,单独再定义一个rate=2r/s的zone挂上去就行,互不影响。    
# 对登录接口单独限流:每秒2个,突发5个
limit_req_zone $binary_remote_addr zone=login_limit:10m rate=2r/s;

location /login.php {
limit_req zone=login_limit burst=5 nodelay;
# 被限流的请求返回429而不是默认503
limit_req_status 429;
fastcgi_pass 127.0.0.1:9000;
}
    验证很简单:reload之后用ab压一下,ab -n 200 -c 20 https://你的域名/,看返回里有没有429或503;同时tail -f日志确认正常用户没被误伤。限流阈值别拍脑袋定,先统计自己站点的正常峰值,设成峰值的两倍左右再逐步收紧。

B | 限流是防守,如果卡死自己人就本末倒置了。    数据来源:nginx.org官方文档 ngx_http_limit_req_module 模块说明

        
    

申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!。

Current article:http://fzfvxz.shengyaodanrongchui.buzz/news/20260826_6144480.html

Published on:13:51:16


人的价值

城之源_Active users

女子遭丈夫打死_Hottest this week