Uptime Kuma 监测 PHP 服务(HTTPS探针)+ Nginx 配置
一、Uptime Kuma 配置 HTTPS 探针监测 PHP 服务状态
核心思路:通过Uptime Kuma的HTTP(S) 探针访问指定的php网址,验证PHP-FPM服务及Nginx反向代理的可用性,需先确保该status.php文件存在且可正常返回状态。
例如:
https://www.example.com/server/test/php/api/status.php
具体配置步骤
-
准备 PHP 状态文件:在 Nginx 根目录的
server/test/php/api/目录下创建status.php,写入基础检测代码(验证PHP解析、服务连通性):<?php // 简单的PHP服务状态检测,返回 JSON 格式更易被Uptime Kuma识别 header('Content-Type: application/json; charset=utf-8'); $status = [ 'code' => 200, 'status' => 'ok', 'php_version' => phpversion(), 'time' => date('Y-m-d H:i:s') ]; echo json_encode($status); exit; -
Uptime Kuma 添加监控项
登录 Uptime Kuma 后台,点击
添加新监控。项 值 备注 监控类型 HTTP(s) URL https://www.example.com/server/test/php/api/status.php 心跳间隔 300 300秒=5分钟 重试次数 1 心跳重试间隔 同 心跳间隔请求超时 10 10秒 连续失败时重复发送通知的间隔次数 0 0为禁用重复发送x为每x次失败则重复发送一次证书到期时通知 勾选 忽略 HTTPS 站点的 TLS/SSL 错误 勾选 反转模式 不勾选 最大重定向次数 10 HTTP 选项 方法 GET 请求体编码 JSON 保存后,自动开始监测。
注意:
- 确保
status.php文件权限正确(如Windows下无权限问题,Linux下需www-data可读写);- 若开启了防火墙,需放行
10370端口的入站请求。
二、Nginx配置文件
例如:绑定端口 8888
server {
listen 8888 ssl;
listen [::]:8888 ssl;
server_name localhost www.example.com;
# SSL证书配置(Windows绝对路径)
ssl_certificate C:/nginx/conf/conf.d/ssl/www.example.com.pem;
ssl_certificate_key C:/nginx/conf/conf.d/ssl/www.example.com.key;
# 基础配置
charset utf-8;
root html;
# 日志配置
access_log C:/nginx/logs/https_8888_access.log main;
error_log C:/nginx/logs/https_8888_error.log warn;
# SSL安全配置(原配置保留+小幅强化)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# 隐藏Nginx版本号,减少指纹识别
server_tokens off;
# 错误页配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 核心安全规则:全局PHP禁止访问(白名单外全部拒绝)
location ~ \.php$ {
deny all;
return 403;
}
location / {
index index.html;
}
# 根路径禁止访问
# location / {
# deny all;
# index index.html;
# return 403;
# }
# 静态目录索引配置(原配置完全保留)
location = /server/test/php/api/ {
index /test/php/api/index.html;
}
# 允许访问api.json,禁止缓存(原配置保留)
location = /server/test/php/api/api.json {
root html;
expires -1;
}
# -------------------------- 1. /server/test/php/ 基础接口 --------------------------
location = /server/test/php/basic.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
limit_except GET POST { deny all; }
fastcgi_connect_timeout 30s;
fastcgi_send_timeout 30s;
fastcgi_read_timeout 30s;
}
# -------------------------- 2. /server/test/php/api/ Kuma探针接口 --------------------------
# Uptime Kuma HTTPS 探针核心接口(可加 IP 白名单)
location = /server/test/php/api/status.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
limit_except GET POST { deny all; }
fastcgi_connect_timeout 30s;
fastcgi_send_timeout 30s;
fastcgi_read_timeout 30s;
# 可选:仅允许Uptime Kuma服务器IP访问,取消注释并替换IP
# allow 192.168.1.100;
# deny all;
}
}
三、配置生效与验证
-
Nginx 配置生效
Windows下在Nginx安装目录(
C:/nginx/)执行命令:# 验证配置语法是否正确 nginx -t # 平滑重启Nginx(不中断现有服务) nginx -s reload -
探针地址验证
在浏览器/Postman中访问
https://work.yogile.site:10370/server/test/php/api/status.php,若返回如下JSON内容,说明配置正常:{"code":200,"status":"ok","php_version":"7.4.33","time":"2025-10-20 10:00:00"} -
Uptime Kuma监控验证
查看监控项的状态,若显示Online,说明PHP服务监测成功;若显示Offline,排查以下点:
-
Nginx配置是否重载成功;
-
status.php文件路径是否正确; -
PHP-FPM 服务是否正常运行(
127.0.0.1:9000是否可连通); -
服务器 8888 端口是否放行。
-
四、扩展建议
-
若为Linux服务器,需给Nginx日志目录、PHP文件配置正确的权限(如
chown -R www-data:www-data 日志目录/PHP目录); -
可在 Uptime Kuma中 为该监控项配置告警规则(如邮件、钉钉、企业微信),当PHP服务宕机时及时通知;
-
定期更新 Nginx 和 PHP 版本,修复安全漏洞;
-
若需限制探针访问来源,可在
status.php的location中添加allow 你的Uptime Kuma服务器IP; deny all;,仅允许 Uptime Kuma 服务器访问。

浙公网安备 33010602011771号