• nginx ---对客户端进行限制的相关配置


      一、限制响应给客户端的传输速率,单位是bytes/second默认值0表示无限制

    limit_rate rate;   语境:httpserverlocation,if in location

      1、生成一百兆的文件

    dd if=/dev/zero of=test.img bs=1M count=100

    2、直接下载

    [18:47:21 root@localhost ~]#wget www.a.net/test.img
    --2021-05-31 18:47:37--  http://www.a.net/test.img
    Resolving www.a.net (www.a.net)... 192.168.1.5
    Connecting to www.a.net (www.a.net)|192.168.1.5|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 104857600 (100M) [application/octet-stream]
    Saving to: ‘test.img.1100%[=========================================================================>] 104,857,600  124MB/s   in 0.8s   
    
    2021-05-31 18:47:38 (124 MB/s) - ‘test.img.1’ saved [104857600/104857600]

    3、限定10k 默认是字节为单位

    server {
            server_name www.a.net;
            root /data/site1;
            limit_rate 10k ;
            location /about {
                    root /opt/testdir/;
                    index test.html;
            }
            location /test1 {
            root /opt/;
            try_files $uri $uri.jpg =404;
            }
    
            error_page 404 =200  /404.html;
            location = /404.html {
            }
    }           

    4、测试下载

    [18:50:39 root@localhost ~]#wget www.a.net/test.img
    --2021-05-31 18:50:39--  http://www.a.net/test.img
    Resolving www.a.net (www.a.net)... 192.168.1.5
    Connecting to www.a.net (www.a.net)|192.168.1.5|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 104857600 (100M) [application/octet-stream]
    Saving to: ‘test.img.20% [                                                                          ] 491,520     9.97KB/s  eta 2h 47m

      二、限制客户端使用除了指定的请求方法之外的其它方法

    limit_except method ... { ... },仅用于location

    1、测试访问,默认是不支持

    curl -X OPTIONS  192.168.1.5
    <html>
    <head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    <hr><center>nginx/1.20.1</center>
    </body>
    </html>

    2、允许192.168.1.4这个网段可以GET,其他都拒绝

    server {
            server_name www.a.net;
            root /data/site1;
            limit_rate 10k ;
            location / {
                limit_except GET {
                    allow 192.168.1.4;
                    deny all;
                    }
            }
    
            location /about {
                    root /opt/testdir/;
                    index test.html;
            }
            location /test1 {
            root /opt/;
            try_files $uri $uri.jpg =404;
            }
    
            error_page 404 =200  /404.html;
            location = /404.html {
            }
    }
    ------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- 博客均为个人笔记,无所追求,仅供参考~~~ QQ--2382990774
  • 相关阅读:
    【转载】为什么CPU有多层缓存
    【转载】二叉树的基本概念和实现
    【转载】如何系统地自学 Python?
    【原文】前端程序员必须知道的高性能Javascript知识
    【转载】重磅!中国人工智能/机器人/无人机创业公司100 | 智能内参
    【转载】分析重装系统也无法清除的鬼影病毒
    【转载】UML类图知识整理
    【转载】.NET程序员走向高端必读书单汇总
    【转载】齐次坐标的理解
    59. Spiral Matrix II
  • 原文地址:https://www.cnblogs.com/alexlv/p/14832690.html
Copyright © 2020-2023  润新知