nginx中http-sysguard模塊
一、作用
防止因nginx并發(fā)訪問(wèn)量過(guò)高或者遭受攻擊造成服務(wù)器宕機(jī),可根據(jù)負(fù)載設(shè)置界面跳轉(zhuǎn)。
二、安裝配置
1.下載模塊軟件包
wget https://github.com/alibaba/nginx-http-sysguard/archive/master.zip unzip /opt/master.zip
2.給nginx打nginx_sysguard補(bǔ)丁
cd /nginx源文件目錄 patch -p1 < nginx-http-sysguard-master/nginx_sysguard_1.3.9.patch
3.編譯nginx添加模塊
nginx -V查看nginx編譯選項(xiàng)
[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可執(zhí)行程序
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp ./objs/nginx /usr/local/nginx/sbin/
4.配置nginx文件
添加如下內(nèi)容,可在http、server、location段配置,load值根據(jù)實(shí)際需求自行調(diào)節(jié)。
sysguard on;
sysguard_load load=0.01 action=/loadlimit;
sysguard_mem swapratio=20% action=/swaplimit;
location = /loadlimit {
return 503;
}
location /swaplimit {
return 503;
}可修改配置頁(yè)面跳轉(zhuǎn)
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(放到項(xiàng)目根目錄)
<!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>國(guó)家海洋博物館</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>太熱情了,請(qǐng)稍后再來(lái)吧</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>到此這篇關(guān)于nginx中http-sysguard模塊的文章就介紹到這了,更多相關(guān)nginx http-sysguard模塊內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- nginx?添加http_stub_status_module模塊
- Nginx流量拷貝ngx_http_mirror_module模塊使用方法詳解
- Nginx之Http模塊系列之a(chǎn)utoindex模塊的具體使用
- nginx http模塊數(shù)據(jù)存儲(chǔ)結(jié)構(gòu)小結(jié)
- 詳解nginx使用ssl模塊配置支持HTTPS訪問(wèn)
- nginx使用ssl模塊配置支持HTTPS訪問(wèn)的方法
- 詳解nginx使用ssl模塊配置HTTPS支持
- 詳解Nginx服務(wù)器的nginx-http-footer-filter模塊配置
- nginx中使用nginx-http-concat模塊合并靜態(tài)資源文件
相關(guān)文章
一篇文章快速掌握Nginx部署前端項(xiàng)目(Nginx安裝配置及部署都非常詳細(xì)!)
這篇文章主要給大家介紹了關(guān)于如何通過(guò)一篇文章快速掌握Nginx部署前端項(xiàng)目的相關(guān)資料,文中從Nginx安裝配置及部署都非常詳細(xì)哦,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-01-01
nginx負(fù)載均衡配置,宕機(jī)自動(dòng)切換方式
這篇文章主要介紹了nginx負(fù)載均衡配置,宕機(jī)自動(dòng)切換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn)
本文主要介紹了Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
Tomcat請(qǐng)求處理在源碼中的輪轉(zhuǎn)解析
這篇文章主要為大家介紹了Tomcat請(qǐng)求處理在源碼中的輪轉(zhuǎn)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
比較完整的Nginx配置文件nginx.conf常用參數(shù)中文詳解
這篇文章主要介紹了比較完整的Nginx配置文件nginx.conf常用參數(shù)中文詳解,需要的朋友可以參考下2015-07-07
Nginx 如何部署指定文件夾下的項(xiàng)目(本地測(cè)試)
這篇文章主要介紹了Nginx 如何部署指定文件夾下的項(xiàng)目(本地測(cè)試),分為配置vue.config.js,指定生成環(huán)境的包,配置路由模式為hash(history模式刷新后,找不到頁(yè)面),本文講解的非常詳細(xì),需要的朋友可以參考下2024-01-01

