V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Recommended Services
Amazon Web Services
LeanCloud
New Relic
ClearDB
yagamil
V2EX  ›  云计算

nginx 限制访问频率 [WordPress]

  •  
  •   yagamil · 2022-04-21 17:20:54 +08:00 · 2529 次点击
    这是一个创建于 735 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在本地测试静态 html 文件的时候问没有问题。

    静态 html 时 nginx 配置

    在 http 块

    limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/m;
    

    1 分钟限制访问 1 次

    在 server 块

        location /test.html {
            root /home/admin/www;
            limit_req zone=req_zone;
            }
            
    

    python 使用 requests 压测,除了第一次返回 200 ,其余都是 503 。

    而在 wordpress 的 nginx 里面: http 块不变,

    server 块如下:

        location ~ \.php$ {
            root           /var/www/html;
            fastcgi_pass   php-mysql:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        
        location ~ \wp-login.php$ {
         limit_req zone=req_zone;
         }
    
    

    同样的压测代码,发现限制不起作用。 请教下运维的高手同学,哪里出问题了。

    alvinbone88
        1
    alvinbone88  
       2022-04-21 20:04:29 +08:00
    location 顺序问题,下面的那个不会被匹配到
    以及,匹配 wp-login 的那个正则有问题,能匹配到也只是碰巧
    yagamil
        2
    yagamil  
    OP
       2022-04-22 00:23:36 +08:00
    @alvinbone88 这个是拷贝网上的。
    我自己改成
    location = /wp-login.php {
    ...}
    也不行
    alvinbone88
        3
    alvinbone88  
       2022-04-22 10:41:31 +08:00
    还要在匹配 wp-login 的配置里加上 fastcgi_pass
    yagamil
        4
    yagamil  
    OP
       2022-05-07 15:46:36 +08:00
    @alvinbone88 谢谢,我去试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   978 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:47 · PVG 05:47 · LAX 14:47 · JFK 17:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.