Linux环境下WordPress站点错误监控咨询(含Monit配置问题)
WordPress站点错误消息监控方案(开源免费工具)
一、修复Monit配置问题
你之前的Monit规则写法有误,正确的URL内容检查需要明确完整请求参数,且要注意匹配逻辑(是包含目标错误文本,而非严格匹配整个页面)。同时可以自定义告警消息,避免模糊的"protocol failed"提示。
正确的Monit配置示例
针对你需要监控的错误,可按以下方式配置:
# 监控站点核心内容类错误 check host wordpress_site with address example.com if failed url https://example.com method GET status 200 content = "Error establishing database connection" then alert with "WordPress: 数据库连接失败" if failed url https://example.com method GET status 200 content = "Error establishing a Redis connection" then alert with "WordPress: Redis连接失败" if failed url https://example.com method GET status 200 content = "There has been a critical error on your website" then alert with "WordPress: 站点发生严重错误" # 监控HTTP状态类错误 check host wordpress_status with address example.com # 监控站点无法访问的情况 if failed url https://example.com method GET timeout 10 seconds then alert with "WordPress: 站点无法访问(This site can't be reached)" # 监控404错误 if failed url https://example.com method GET status 404 content = "Page Not Found" then alert with "WordPress: 页面不存在(404错误)" # 监控维护模式 check host wordpress_maintenance with address example.com if failed url https://example.com method GET status 503 content = "Briefly unavailable for scheduled maintenance" then alert with "WordPress: 站点进入维护模式"
关键注意点:
- 必须指定完整的
https://协议URL,Monit需要明确请求协议 content = "xxx"是检查页面包含该文本,无需匹配整个页面内容- 自定义
alert with内容,让告警直接说明错误类型,避免模糊提示 - 结合状态码+内容双重校验,减少误报(比如维护模式通常返回503状态码)
二、替代开源监控工具推荐
如果Monit的HTTP内容检查满足不了需求,可试试这些工具:
1. Uptime Kuma
轻量易用的开源监控工具,支持HTTP/HTTPS内容匹配:
- 添加监控项时开启"关键字监控",指定要检测的错误文本,页面出现该文本时触发告警
- 支持邮件、Telegram、Discord等多种告警方式
- 自带Web可视化界面,直观查看监控状态
2. Nagios Core
老牌开源监控系统,灵活性极高:
- 通过
check_http插件实现页面内容检查,示例命令:check_http -H example.com -u / -s "Error establishing database connection" - 可自定义告警消息,结合Nagios通知系统发送精准告警
- 适合多站点、多服务的复杂监控场景
3. 自定义脚本 + Cron
如果不想用复杂工具,可写简单脚本结合定时任务实现:
#!/bin/bash TARGET_URL="https://example.com" LOG_FILE="/var/log/wp_error_monitor.log" ALERT_EMAIL="your-email@example.com" # 定义需要监控的错误消息 ERROR_MESSAGES=( "Error establishing database connection" "Error establishing a Redis connection" "There has been a critical error on your website" "Briefly unavailable for scheduled maintenance" "Page Not Found" ) # 检查页面内容中的错误 for ERROR in "${ERROR_MESSAGES[@]}"; do if curl -s "$TARGET_URL" | grep -q "$ERROR"; then ALERT_MSG="$(date +'%Y-%m-%d %H:%M:%S'): 检测到错误: $ERROR" echo "$ALERT_MSG" >> "$LOG_FILE" # 发送邮件告警,可根据需求替换为其他方式 echo "$ALERT_MSG" | mail -s "WordPress站点告警" "$ALERT_EMAIL" fi done # 检查站点是否无法访问 if ! curl -s -f "$TARGET_URL" > /dev/null; then ALERT_MSG="$(date +'%Y-%m-%d %H:%M:%S'): 站点无法访问: This site can't be reached" echo "$ALERT_MSG" >> "$LOG_FILE" echo "$ALERT_MSG" | mail -s "WordPress站点告警" "$ALERT_EMAIL" fi
将脚本保存为wp_error_monitor.sh,添加可执行权限chmod +x wp_error_monitor.sh,然后用Cron设置定时执行(比如每5分钟一次):
*/5 * * * * /path/to/wp_error_monitor.sh
三、额外优化建议
- 针对WordPress的后台错误,可同时监控
wp-content/debug.log文件,当出现新的错误日志时触发告警(Monit支持文件内容监控) - 设置合理的监控间隔(1-5分钟),避免频繁请求给服务器造成额外负载
- 对于带缓存的页面,可添加缓存排除参数(比如
?nocache=1),确保监控到真实页面状态
内容的提问来源于stack exchange,提问作者user3327338
相关产品推荐
相关产品推荐

