nginx监控模块 📅 发布时间:2026/7/8 21:04:21 👁️ 浏览次数: 1. ✅nginx的web监控检查下当前nginx是否有监控模块#查看nginx支持哪些模块 [rootweb01 ~]# nginx -V | grep status configure arguments: --prefix/etc/nginx --sbin-path/usr/sbin/nginx --modules-path/usr/lib64/nginx/modules --conf-path/etc/nginx/nginx.conf --error-log-path/var/log/nginx/error.log --http-log-path/var/log/nginx/access.log --pid-path/var/run/nginx.pid --lock-path/var/run/nginx.lock --http-client-body-temp-path/var/cache/nginx/client_temp --http-proxy-temp-path/var/cache/nginx/proxy_temp --http-fastcgi-temp-path/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path/var/cache/nginx/uwsgi_temp --http-scgi-temp-path/var/cache/nginx/scgi_temp --usernginx --groupnginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -fPIC --with-ld-opt-Wl,-z,relro -Wl,-z,now -pie使用1.修改status配置文件 [rootweb01 ~]# vim /etc/nginx/conf.d/status.conf server { listen 80; server_name status.linux.cn; access_log off; error_log /var/log/nginx/status-error.log; location / { allow 10.0.0.1; allow 172.16.1.0/24; deny all; stub_status; } } 2.重启nginx服务 systemctl reload nginx #查看nginx状态 [rootweb01 ~]# curl -H Host:status.linux.cn http://172.16.1.7 Active connections: 4 server accepts handled requests 5 5 6 Reading: 0 Writing: 1 Waiting: 3status指令结果说明说明备注Active connections已经建立连接的数量.4层 实时数据当前网站并发访问数量accepts总数(持续增加),nginx已经接收了多少个3次握手请求绝大部分情况accepts与handlers一致类似handled总数(持续增加),nginx已经处理的请求数量requests总数(持续增加),nginx已经收到了多少http请求数量比accepts数量多.(连接建立后,连接可以重复使用)Reading实时数据.正在读取客户端请求(头,主体)数量Writing实时数据.正在返回客户端响应(头,主体)数量Waiting实时数据.空闲的连接数量.(3次握手建立连接,发出http请求,连接保留,此时没有请求使用连接)压力测试ab -H Host:lb.linux.cn -n 999999 -c 10 -k http://10.0.0.7/ -H 修改请求头信息 -n 请求数量 -c 并发数量 -k 启动长连接 ab结果 Percentage of the requests served within a certain time (ms) 50% 0 66% 1 75% 1 80% 1 90% 1 #90%的请求的时间1ms 95% 1 98% 2 99% 3 100% 44 (longest request)2. ✅nginx负载监控第三方模块nginx没有安装,nginx官方开源也没有,nginx官方商业版有2.1. upstream_check模块下载这个模块的代码并且编译安装nginx准备使用tengine实现(代码中包含常用的nginx第3方模块)既要编译安装tengine,又要保持与yum安装的一致性编译安装nginx/tengine--nginx命令1.下载tengine代码 wget https://tengine.taobao.org/download/tengine-3.1.0.tar.gz 2.安装依赖 yum install -y openssl-devel pcre-devel 3.解压 tar xf tengine-3.1.0.tar.gz 4.配置 ./configure --prefix/etc/nginx --sbin-path/usr/sbin/nginx --modules-path/usr/lib64/nginx/modules --conf-path/etc/nginx/nginx.conf --error-log-path/var/log/nginx/error.log --http-log-path/var/log/nginx/access.log --pid-path/var/run/nginx.pid --lock-path/var/run/nginx.lock --http-client-body-temp-path/var/cache/nginx/client_temp --http-proxy-temp-path/var/cache/nginx/proxy_temp --http-fastcgi-temp-path/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path/var/cache/nginx/uwsgi_temp --http-scgi-temp-path/var/cache/nginx/scgi_temp --usernginx --groupnginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -fPIC --with-ld-opt-Wl,-z,relro -Wl,-z,now -pie \ --add-module./modules/ngx_http_upstream_check_module \ --add-module./modules/ngx_http_upstream_session_sticky_module 5.编译 make -j nproc 6.传输 objs/nginx 到lb01 scp objs/nginx root172.16.1.7:~ 7.备份旧命令然后更新nginx mv /sbin/nginx /sbin/nginx-1.26 8.重启Nginx systemctl restart nginx 9.curl检查 curl -v http://10.0.0.7/ 有Tengine即可2.2. 配置使用模块展示负载均衡分组中,节点的可用情况使用tcp仅仅检查后端节点的端口端口是否可以访问check interval3000 rise2 fall5 timeout1000 typetcp port80; interval3000 3000ms3m每隔3秒检查1 次. rise2 成功2次及以上认为节点可用. fall5 失败5次及以上认为节点不可用. typehttp; 类型 http或tcp port80使用http协议检查使用浏览器访问(curl)指定Host,指定URI,指定UA,更加接近与用户访问.upstream lb_pool { server 10.0.0.7:80 weight1; server 10.0.0.8:80 weight1; check interval3000 rise2 fall5 timeout1000 typehttp; check_http_send HEAD / HTTP/1.0\r\nHost: lb.linux.cn\r\nUser-Agent: lb_check\r\n\r\n; check_http_expect_alive http_2xx http_3xx; }监控lb站点即可lb01配置文件(nginx替换成tengine后)web01、web02配置文件及目录、用户要一致upstream lb_pool { server 10.0.0.7:80 weight1; server 10.0.0.8:80 weight1; check interval3000 rise2 fall5 timeout1000 typehttp; check_http_send HEAD / HTTP/1.0\r\nHost: lb.linux.cn\r\nUser-Agent: lb_check\r\n\r\n; check_http_expect_alive http_2xx http_3xx; } server { listen 80; server_name lb.linux.cn; access_log /var/log/nginx/lb-access.log main; error_log /var/log/nginx/lb-error.log notice; location / { proxy_pass http://lb_pool; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-Ip $remote_addr; } location /lb_status { allow 10.0.0.1; allow 172.16.1.0/24; deny all; check_status; } location /ngx_status { allow 10.0.0.1; allow 172.16.1.0/24; deny all; stub_status; } }2.3. 参数详解参数含义interval3000检查间隔为 3 秒单位毫秒rise2请求成功多少次后标记为正常fall3请求失败多少次后标记为异常timeout1000单次请求超时时间单位毫秒typehttp使用 HTTP 类型检查也可以是 tcp、ssl_hello、mysql、ajp 等check_http_send发送的 HTTP 请求内容check_http_expect_status期望返回的状态码范围2.4. 浏览器查看3. ✅nginx平滑升级使用restart重启,升级会导致一些已建立的连接断开1.备份旧的nginx命令 mv /sbin/nginx /sbin/nginx-1.26 2.拷贝旧的nginx命令到/sbin/目录下 mv nginx /sbin/nginx 3.使用kill -USR2 pid(旧的),保持旧的命令的进程不关,用新的命令启动新的进程 kill -USR2 pid 4.过一段时间使用kill命令将旧的进程关闭 kill pid(旧的)4. ✅跳转功能/模块server { listen 80; server_name baidu.linux.cn; return 301 http://www.baidu.com$request_uri; }rewrite模块核心指令说明应用场景return指令URL跳转301302跳转更加简单,一般使用ngx变量rewrite指令URL跳转复杂跳转,需要使用正则匹配setngx创建变量创建或修改变量if判断非uri的内容(ngx中的if只有简单分支)跳转何时使用新旧域名www.360buy.com -- www.jd.comhttp--https伪静态运维人员,搜索引擎喜欢收集静态页面,动态页面搜索引擎不喜欢.动态页面 --静态 urlhttps://search.jd.com/Search? keywordssdencutf- 8wqssdpvid0984120ca84642988f1b647de07d8 537 ? 动态请求 https://search.jd.com/lidao.html实现新老域名跳转(或http--https)re.linux.cn ---www.baidu.com 302 临时给网站设置1个开关,网站是否处于维护模式503.方法1: 子配置文件创建变量,flag等于1或0.人工修改. 如果变量为1则return 503. # set $flag 1; # if ( $flag 1 ) { # return 503; # } 方法2: 子配置文件加入判断文件是否存在weihu.html 文件存在则输出503. if ( -f /etc/nginx/weihu.txt ) { return 503; } [rootweb01 /etc/nginx/conf.d]# cat re.linux.cn.conf server { listen 80; server_name re.linux.cn; root /app/code/re; # set $flag 1; # if ( $flag 1 ) { # return 503; # } if ( -f /etc/nginx/weihu.txt ) { return 503; } location / { index index.html; } }网站只准许GET,POST,HEAD请求,其他请求方法都拒绝405[rootweb01 /etc/nginx/conf.d]# cat re.linux.cn.conf server { listen 80; server_name re.linux.cn; #set $flag 1; if ( $request_method !~^(GET|POST|HEAD)$ ) { return 405; } set $file /etc/nginx/weihu.html; if ( -f $file ) { return 503; } root /app/code/re; location / { index index.html; } } curl -X PUT -H Host:re.linux.cn http://10.0.0.7 $sent_http_响应头内容 $http_请求头 小写,下划线. $request_method 请求方法 $request_uri 请求uri $status 状态码 $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;
7个实用技巧掌握Java8 CompletableFuture异步编程精髓 7个实用技巧掌握Java8 CompletableFuture异步编程精髓 【免费下载链接】learn-java8 项目地址: https://gitcode.com/gh_mirrors/lea/learn-java8 Java8引入的CompletableFuture是处理异步编程的强大工具,它让复杂的异步任务处理变得简单直观。本文将通过实… 2026/7/6 16:32:05
RAG-3-Embeddings 在数学中,向量(也称为欧几里得向量、几何向量),指具有大小(magnitude)和方向的量。它可以形象化地表示为带箭头的线段。箭头所指:代表向量的方向;线段长度:代表向量的大小… 2026/7/8 13:13:17
ansible初体验 1. 选型 工具 说明 缺点 xshell 不适应机器过多场景,需要连接后才能用 forssh/scp密钥认证 密钥认证,免密码登录 scp传输文本/脚本 ssh远程执行命令或脚本 串行 saltstack 需要安装客户端 ansible 无客户端(密钥认证)批… 2026/7/8 0:38:19
3 种 Windows 进程同步机制对比:Event vs Mutex vs Semaphore 在共享内存场景下的性能与选择 Windows共享内存同步机制深度对比:Event、Mutex与Semaphore实战指南引言:共享内存与同步机制的核心挑战在现代Windows系统开发中,进程间通信(IPC)是构建复杂分布式系统的关键技术。共享内存作为最高效的IPC方式之一&am… 2026/7/8 21:03:13
SecureCRT/Xshell 7 配置 sz/rz:5个关键参数优化与常见传输失败排查 SecureCRT/Xshell 7 终极配置指南:5个关键参数优化与Zmodem传输故障深度排查1. 终端工具与Zmodem协议的核心协同机制在远程服务器管理的日常工作中,文件传输如同血管中的血液般重要。不同于常见的SCP/SFTP协议,Zmodem协议以其独特的交互式特性… 2026/7/8 21:01:12
FlyOOBE:让旧电脑也能轻松安装Windows 11的智能助手 FlyOOBE:让旧电脑也能轻松安装Windows 11的智能助手 【免费下载链接】FlyOOBE Fly through your Windows 11 setup 🐝 项目地址: https://gitcode.com/gh_mirrors/fl/FlyOOBE 还在为老电脑无法升级Windows 11而烦恼吗?FlyOOBE是一款专… 2026/7/8 21:01:12
iOS原生能力调用:调用iOS SDK (HealthKit, ARKit)(117) 在跨平台应用开发中,iOS 平台提供了丰富的原生 SDK 以支持健康数据追踪与增强现实体验。其中,HealthKit 用于聚合和读写用户的健康与健身数据,而 ARKit 则负责构建沉浸式的增强现实场景。以下是调用这两个核心 iOS SDK :一、 Heal… 2026/7/8 20:57:11
YOLOv8 + LPRNet 车牌识别实战:PyQt5 界面集成与 4 模型性能对比 YOLOv8 LPRNet 车牌识别实战:PyQt5 界面集成与 4 模型性能对比车牌识别技术作为智能交通系统的核心组件,正在停车场管理、道路执法、安防监控等领域发挥越来越重要的作用。传统OCR方案在面对复杂光照、倾斜车牌或运动模糊时表现不佳,而基于深… 2026/7/8 20:57:11
关于动态规划【力扣583.两个字符串的删除操作的思考】 1、目前动态规划的子序列系列的题目之间的区别与联系【力扣300.最长递增子序列】一个数组,不连续【力扣674.最长连续递增子序列】一个数组,连续【力扣718.最长重复子数组】两个数组,连续【力扣1143.最长公共子序列】两个数组,不连… 2026/7/8 20:55:10
BetterNCM安装器:高效管理网易云插件的最佳选择 BetterNCM安装器:高效管理网易云插件的最佳选择 【免费下载链接】BetterNCM-Installer 一键安装 Better 系软件 项目地址: https://gitcode.com/gh_mirrors/be/BetterNCM-Installer 还在为网易云音乐插件的繁琐安装流程而烦恼吗?BetterNCM安装器是… 2026/7/8 0:02:48
运动控制系统安全设置对比:ECI3808的3种限位保护与急停逻辑实现 运动控制系统安全机制深度解析:限位保护与急停逻辑的设计哲学在精密制造与自动化领域,运动控制系统的安全设计绝非简单的功能堆砌,而是一套融合了机械工程、电气原理和软件算法的防御体系。当一台数控机床以每分钟数万转的速度运转࿰… 2026/7/8 0:06:48
AI大模型应用开发:小白也能抓住的红利风口,收藏这篇入门指南! 文章指出,虽然微软等科技巨头在裁员,但英伟达等公司却在积极扩招AI相关人才,尤其是具身智能、仿真等领域。AI行业正在经历结构性调整,传统岗位被淘汰,而大模型应用开发等新岗位需求旺盛。对于想转行或学习AI的普通人来… 2026/7/8 0:10:49
6个月转型AI工程师:实战路径与核心技能 1. 项目概述:6个月转型AI工程师的可行性路径在2023年大模型技术爆发的背景下,AI工程师岗位需求同比增长217%(LinkedIn数据)。不同于传统算法工程师需要3-5年培养周期,现代AI工程师更侧重工程化落地能力。我在硅谷科技公… 2026/7/7 11:26:57
TPAFE0808与PIC18F87K22的多通道信号采集方案 1. 项目背景与核心需求在工业自动化、医疗设备和科研仪器等领域,多通道信号采集与系统监测是基础且关键的技术需求。传统方案往往面临通道数量不足、信号调理复杂、系统集成度低等问题。TPAFE0808作为一款8通道模拟前端芯片,与PIC18F87K22微控制器的组合… 2026/7/8 20:15:17
STC3115与PIC18LF26K80构建高精度电池管理系统 1. STC3115与PIC18LF26K80在电池管理系统中的核心价值在现代电子设备中,电池管理系统(BMS)的重要性不亚于设备的核心处理器。STC3115作为一款高精度电池电量监测IC,与PIC18LF26K80微控制器的组合,构成了一个既能精确监控又能智能管理的完整解… 2026/7/8 14:25:08