nginx中http-sysguard模块

一、作用

防止因nginx并发访问量过高或者遭受攻击造成服务器宕机,可根据负载设置界面跳转。

二、安装配置

1.下载模块软件包

1
2
wget https://github.com/alibaba/nginx-http-sysguard/archive/master.zip
unzip /opt/master.zip

2.给nginx打nginx_sysguard补丁

1
2
cd /nginx源文件目录
patch -p1

3.编译nginx添加模块

nginx -V查看nginx编译选项

1
2
3
4
5
6
[root@myhost nginx-1.14.0]# nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2o  27 Mar 2018
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/opt/hdlnmp/src/openssl-1.0.2o

重新编译,增加模块

1
2
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/opt/hdlnmp/src/openssl-1.0.2o --add-module=nginx-http-sysguard-master
make

替换nginx可执行程序

1
2
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp ./objs/nginx /usr/local/nginx/sbin/

4.配置nginx文件

添加如下内容,可在http、server、location段配置,load值根据实际需求自行调节。

1
2
3
4
5
6
7
8
9
sysguard on;
sysguard_load load=0.01 action=/loadlimit;
sysguard_mem swapratio=20% action=/swaplimit;
location = /loadlimit {
    return 503;
}
location /swaplimit {
    return 503;
}

可修改配置页面跳转

1
2
3
sysguard on;
sysguard_load load=0.01 action=/crowded.html;
#sysguard_load load=0.01 action=/error_page/index.html;

5.重启nginx

1
service nginx restart

crowded.html(放到项目根目录)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<title>国家海洋博物馆</title>
    .box {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
        /* IE 9 */
        -webkit-transform: translate(-50%, -50%);
        /* Safari and Chrome */
        -o-transform: translate(-50%, -50%);
        /* Opera */
        -moz-transform: translate(-50%, -50%);
        /* Firefox */
    }
     
    .box img {
        display: block;
        width: 3.85rem;
    }
     
    .box p {
        font-size: 0.28rem;
        color: #000;
        text-align: center;
        line-height: 1.5rem;
    }
<div class="box">
    <img decoding="async" src="https://www.2it.club/wp-content/uploads/2024/09/frc-0ffb29a0b4bb14da03b6255b70edf36c.jpeg"><p>太热情了,请稍后再来吧</p>
</div>
 
    (function(doc, win) {
        var docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            recalc = function() {
                var clientWidth = docEl.clientWidth;
                if(!clientWidth) return;
                if(clientWidth >= 750) {
                    docEl.style.fontSize = '100px';
                } else {
                    docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
                }
            };
 
        if(!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        doc.addEventListener('DOMContentLoaded', recalc, false);
    })(document, window)

到此这篇关于nginx中http-sysguard模块的文章就介绍到这了,更多相关nginx http-sysguard模块内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部! 

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/nginx/13030.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部