|
一、作用
防止因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 < nginx-http-sysguard-master/nginx_sysguard_1.3.9.patch
复制代码 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.重启nginxcrowded.html(放到项目根目录)- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
- <meta http-equiv="X-UA-Compatible" content="ie=edge" />
- <title>国家海洋博物馆</title>
- <style type="text/css">
- .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;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <img src="https://img-blog.csdnimg.cn/2022010617585034894.jpeg" />
- <p>太热情了,请稍后再来吧</p>
- </div>
- <script type="text/javascript">
- (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)
- </script>
- </body>
- </html>
复制代码 到此这篇关于nginx中http-sysguard模块的文章就介绍到这了,更多相关nginx http-sysguard模块内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
来源:https://www.jb51.net/server/326510i76.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
|