以下是针对Debian系统上Nginx的监控报警方案,可根据需求选择组合使用:
Nginx状态模块
stub_status
模块,通过http://服务器IP/nginx_status
获取基础指标(如连接数、请求量)。location /stub_status { stub_status on; access_log off; }
,并限制访问IP。日志监控
/var/log/nginx/access.log
和error.log
,使用grep
、awk
等工具过滤异常(如404、500错误)。Logrotate
管理日志轮转,避免文件过大。Prometheus + Grafana
Nginx Exporter
抓取Nginx指标(如请求速率、错误率、上游状态),暴露给Prometheus。Alertmanager
设置阈值报警(如错误率>5%时发送邮件)。apt install prometheus grafana
。Fail2Ban
/etc/fail2ban/jail.local
,启用[nginx]
规则,设置logpath
(指向访问日志)、maxretry
(最大失败次数)等参数。Zabbix/Nagios
Alertmanager
或Zabbix配置邮件通知。参考来源: