我正在尝试通过 http 调用设置和获取 php-fpm 统计信息。我知道可以使用 service status 命令,但我想从我的浏览器中获取它。
我正在运行 php7 和 apache,这是我在服务器配置中所做的。
在 apache 端,我用这个创建了一个虚拟主机:
<LocationMatch "/fpm-status">
Order Allow,Deny
Allow from 127.0.0.1
ProxyPass fcgi://127.0.0.1:9000
</LocationMatch>
在 php 池配置中 (/etc/php/7.0/fpm/pool.d/www.conf) 我有这个:
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 1000
pm.start_servers = 150
pm.min_spare_servers = 50
pm.max_spare_servers = 400
pm.max_requests = 200
pm.process_idle_timeout = 5s
pm.status_path = /fpm-status
但是在重新启动 apache 和 php-fpm 进程后,当我尝试使用 curl 时,我得到了这个输出:
admin@ip-10-3-23-78:~$curl http://localhost/fpm-status
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /fpm-status
on this server.<br />
</p>
</body></html>
admin@ip-10-3-23-78:~$
在 apache 日志文件中我有这个:
==> /var/log/apache2/error.log <==
[Thu Aug 25 13:36:10.776665 2016] [access_compat:error] [pid 12608] [client ::1:23142] AH01797: client denied by server configuration: proxy:fcgi://127.0.0.1:9000
我想知道如何真正设置它。我在谷歌上搜索了很长时间,但没有得到准确的答案,每个人都在尝试自己的方式。 谁负责创建状态页面(在我的例子中是 fpm-status)?何时以及如何生成此页面(我猜是通过 php-fpm 生成的)? 设置页面并从浏览器访问的正确方法是什么?
最佳答案
现在可能有点晚了,但我想用 php-fpm(7.1+)/apache(2.4) 发布一个简单直接的答案来解决这个问题,因为我在网上找到的大多数答案都有些复杂。这是使用需要 unix 套接字与端口映射的默认 php-fpm 设置。
1) 在 /etc/php-fpm.d/www.conf
中,我为下面的 listen sock 设置了以下配置选项并且未注释掉:
listen = /var/run/php-fpm.sock
pm.status_path = /fpm-status
2) 在我的 apache 配置 php-latest.conf
(或类似的)中,我添加了一个匹配项来查找 fpm-status 并将其设置为 proxypass
到 unix套接字并从 fcgi 运行 fpm-status。它还对其进行了限制,因此只有本地主机可以调用它:
<LocationMatch "/fpm-status">
Order Allow,Deny
Allow from 127.0.0.1
ProxyPass unix:/var/run/php-fpm.sock|fcgi://localhost/fpm-status
</LocationMatch>
3) 只需在本地运行 curl
命令即可:
$ curl http://localhost/fpm-status
pool: www
process manager: dynamic
start time: 16/Oct/2019:11:33:25 -0400
start since: 14
accepted conn: 12
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 38
active processes: 2
total processes: 40
max active processes: 5
max children reached: 0
slow requests: 0
关于php - 使用 php7 和 apache 设置 php-fpm 状态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39144450/