我正在尝试设置并获得php-fpm统计与http调用。我知道可以使用服务状态命令,但我想从我的浏览器中获得。
我正在运行php7和apache,这是我在服务器配置中所做的。
在apache端,我创建了一个vhost:<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
我想知道如何真正设置这个。我在谷歌上搜索了很长时间,没有得到确切的答案,每个人都在尝试自己的方法。谁负责创建状态页(在我的例子中是 fm -status)?何时以及如何生成这个页面(通过php-fpm我猜)?设置页面并从浏览器访问的正确方法是什么?
现在可能有点晚了,但是我想发布一个直接简单的答案来解决这个问题php-fpm(7.1+)/apache(2.4),因为我在网上找到的大多数答案都有点令人费解。这是使用默认的php-fpm设置,需要unix套接字与端口映射。
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
(或类似的),我添加了一个匹配,查找ffm -status并将其设置为proxypass
到unix套接字并从fcgi运行ffm -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
我遇到了同样的问题,花了几个小时来解决我们的安装问题。不幸的是,我不能回答你在那里提出的所有问题,这主要是一个工作解决方案的tile"设置php-fpm状态页与php7和apache"
我们开始(Ubuntu 16.04):
第一步:需要的东西检查一下你是否安装了类似的东西:
apt-get -y install apache2
apt-get -y install libapache2-mod-fastcgi php7.0-fpm php7.0
a2enmod actions fastcgi alias
systemctl restart apache2.service
步骤2:设置fastcgi在/etc/apache2/mod -available/fastcgi.conf(或类似的)中添加以下内容:
<IfModule mod_fastcgi.c>
# Define a named handler
AddHandler php7-fcgi .php
# Generate an alias pointing to /usr/lib/cgi-bin/php[VersionNumber]-fcgi
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
# Configure an external server handling your upcoming requests (note where the alias is pointing towards)
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
# only on if fpm-status is match. You might want to put this into your concrete vhost.conf file. For the testing, fastcgi.conf should work.
<LocationMatch "/fpm-status">
# set the before defined handler here
SetHandler php7-fcgi
# use the handler for the action handling virtual requests
Action php7-fcgi /php7-fcgi virtual
</LocationMatch>
</IfModule>
步骤3:检查/etc/php/7.0/fpm/pool.d/www.conf确保取消状态路径的注释:
pm.status_path = /fpm-status
步骤4:保护页面(可选)在投入生产之前,以某种方式确保这一点当然是明智的,例如:
Order deny,allow
Deny from all
Allow from [Some-IP]
希望对大家有帮助。
如果你在apache服务器上运行其他web应用程序,很可能其中一个应用程序附带的.htaccess
文件会干扰处理/staus
页面(或者你在php-fpm池配置中命名的页面)。
我最近在nextcloud实例中遇到了这个问题。在nextcloud-(apache)-配置中,将URL列入白名单并禁用此路径(RewriteEngine Off
)的.htaccess
覆盖,使页面可访问。确保用正确的路径替换到套接字的路径(这是Ubuntu 16.04的示例)。
<FilesMatch "^ping|status$">
RewriteEngine Off
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
注释正如在注释中指出的,正确的指令可能是<Location "^ping|status$">
而不是<FilesMatch>
。
套接字路径定义在/etc/php/7.2/fpm/pool.d/www.conf
(listen = /run/php/php7.2-fpm.sock
)在ubuntu默认版本
如果出现权限错误,请尝试添加
listen.mode = 0666
/etc/php/7.0/fpm/pool.d/www.conf
这是必要的,我得到整个fastcgi堆栈php-fpm正常运行,尽管我仍然无法查看状态页,并得到一个404错误,当我尝试