一、作用
防止因nginx并发访问量过高或者遭受攻击造成服务器宕机,可根据负载设置界面跳转。
二、安装配置
1.下载模块软件包
wget https://github.com/alibaba/nginx-http-sysguard/archive/master.zip unzip /opt/master.zip
2.给nginx打nginx_sysguard补丁
cd /nginx源文件目录 patch -p1
3.编译nginx添加模块
nginx -V查看nginx编译选项
[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
重新编译,增加模块
./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可执行程序
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值根据实际需求自行调节。
sysguard on; sysguard_load load=0.01 action=/loadlimit; sysguard_mem swapratio=20% action=/swaplimit; location = /loadlimit { return 503; } location /swaplimit { return 503; }
可修改配置页面跳转
sysguard on; sysguard_load load=0.01 action=/crowded.html; #sysguard_load load=0.01 action=/error_page/index.html;
5.重启nginx
service nginx restart
crowded.html(放到项目根目录)
国家海洋博物馆 .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; }(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俱乐部!