nginx中http-sysguard模塊
一、作用
防止因nginx并發(fā)訪問量過高或者遭受攻擊造成服務(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; }
可修改配置頁面跳轉(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>國家海洋博物館</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>
到此這篇關(guān)于nginx中http-sysguard模塊的文章就介紹到這了,更多相關(guān)nginx http-sysguard模塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- nginx?添加http_stub_status_module模塊
- Nginx流量拷貝ngx_http_mirror_module模塊使用方法詳解
- Nginx之Http模塊系列之a(chǎn)utoindex模塊的具體使用
- nginx http模塊數(shù)據(jù)存儲結(jié)構(gòu)小結(jié)
- 詳解nginx使用ssl模塊配置支持HTTPS訪問
- nginx使用ssl模塊配置支持HTTPS訪問的方法
- 詳解nginx使用ssl模塊配置HTTPS支持
- 詳解Nginx服務(wù)器的nginx-http-footer-filter模塊配置
- nginx中使用nginx-http-concat模塊合并靜態(tài)資源文件
相關(guān)文章
一篇文章快速掌握Nginx部署前端項(xiàng)目(Nginx安裝配置及部署都非常詳細(xì)!)
這篇文章主要給大家介紹了關(guān)于如何通過一篇文章快速掌握Nginx部署前端項(xiàng)目的相關(guān)資料,文中從Nginx安裝配置及部署都非常詳細(xì)哦,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2023-01-01Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn)
本文主要介紹了Nginx配置本地圖片服務(wù)器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12比較完整的Nginx配置文件nginx.conf常用參數(shù)中文詳解
這篇文章主要介紹了比較完整的Nginx配置文件nginx.conf常用參數(shù)中文詳解,需要的朋友可以參考下2015-07-07Nginx 如何部署指定文件夾下的項(xiàng)目(本地測試)
這篇文章主要介紹了Nginx 如何部署指定文件夾下的項(xiàng)目(本地測試),分為配置vue.config.js,指定生成環(huán)境的包,配置路由模式為hash(history模式刷新后,找不到頁面),本文講解的非常詳細(xì),需要的朋友可以參考下2024-01-01