当前位置: 代码网 > it编程>游戏开发>ar > nginx中http-sysguard模块

nginx中http-sysguard模块

2024年08月26日 ar 我要评论
一、作用防止因nginx并发访问量过高或者遭受攻击造成服务器宕机,可根据负载设置界面跳转。二、安装配置1.下载模块软件包wget https://github.com/alibaba/nginx-ht

一、作用

防止因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.重启nginx

service nginx restart

crowded.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模块内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com