简体   繁体   English

使用 php7 和 apache 设置 php-fpm 状态页面

[英]Set up php-fpm status page with php7 and apache

I'm trying to set up and get php-fpm stats with a http call.我正在尝试通过 http 调用设置和获取 php-fpm 统计信息。 I know it's possible to use the service status command, but I would like to get that from my browser.我知道可以使用service status命令,但我想从我的浏览器中获取它。

I'm running php7, and apache, and this is what I did in my server configuration.我正在运行 php7 和 apache,这就是我在服务器配置中所做的。

at apache side, I create a vhost with this :在 apache 端,我用这个创建了一个虚拟主机:

<LocationMatch "/fpm-status">
             Order Allow,Deny
             Allow from 127.0.0.1
             ProxyPass fcgi://127.0.0.1:9000
</LocationMatch>

In the php pool configuration ( /etc/php/7.0/fpm/pool.d/www.conf ) I have this :在 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

but after restart apache and php-fpm process, when I try with curl I get this output :但是在重新启动 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:~$ 

And in the apache log file I have this :在 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

I would like to know how to really set this up.我想知道如何真正设置它。 I've googled for long time and didn't get a precise answer, every one is trying his way.我在谷歌上搜索了很长时间并没有得到确切的答案,每个人都在尝试自己的方式。 Who is reponsible to create the status page ( fpm-status in my case)?谁负责创建状态页面(在我的例子中是fpm-status )? When and how this page is generated (by php-fpm I guess)?何时以及如何生成此页面(我猜是 php-fpm)? What is the right way to set the page up and accessible from a browser?设置页面并从浏览器访问的正确方法是什么?

Might be a bit late now but I wanted to post a straight forward simple answer to this issue with php-fpm(7.1+)/apache(2.4) as most of the answers I found online were a bit convoluted.现在可能有点晚了,但我想用 php-fpm(7.1+)/apache(2.4) 发布一个直接简单的答案,因为我在网上找到的大多数答案都有些复杂。 This is using the default php-fpm settings that require unix sockets vs port mapping.这是使用需要 unix 套接字与端口映射的默认 php-fpm 设置。

1) Within /etc/php-fpm.d/www.conf , I have the following config options set for listen sock below and uncommented out: 1)在/etc/php-fpm.d/www.conf ,我为下面的监听袜子设置了以下配置选项并取消注释:

listen = /var/run/php-fpm.sock

pm.status_path = /fpm-status

2) With my apache config php-latest.conf (or similar) I added a match that looked for fpm-status and set it to proxypass to the unix socket and run the fpm-status from fcgi. 2) 使用我的 apache 配置php-latest.conf (或类似的),我添加了一个匹配来查找 fpm-status 并将其设置为proxypass到 unix 套接字并从 fcgi 运行 fpm-status。 It also restricts it so only localhost can call it:它还限制它,因此只有本地主机可以调用它:

<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) Just simply run the curl command locally: 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

I suffered the same problem and put a few hours in there to solve it for our installations.我遇到了同样的问题,并在那里花了几个小时来解决我们的安装问题。 Unfortunately I can not answer all questions you have put in there, this is mainly a working solution for the tile "Set up php-fpm status page with php7 and apache"不幸的是,我无法回答您在那里提出的所有问题,这主要是“使用 php7 和 apache 设置 php-fpm 状态页面”磁贴的有效解决方案

Here we go (Ubuntu 16.04):我们开始吧(Ubuntu 16.04):

Step 1: Things needed Just check if you installed this stuff similarly:第 1 步:需要的东西只需检查您是否安装了类似的东西:

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

Step 2: Setup fastcgi In /etc/apache2/mods-available/fastcgi.conf (or similar) put the following:第 2 步:设置 fastcgi在 /etc/apache2/mods-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>

Step 3: Check your /etc/php/7.0/fpm/pool.d/www.conf Make sure do uncomment the status path:第 3 步:检查您的 /etc/php/7.0/fpm/pool.d/www.conf确保取消注释状态路径:

pm.status_path = /fpm-status

Step 4: Secure the page (optional) Before going into production, it is certainly wise to secure this somehow, eg:第 4 步:保护页面(可选)在投入生产之前,以某种方式保护它当然是明智的,例如:

 Order deny,allow
 Deny from all
 Allow from [Some-IP]

Hope this helps, cheers.希望这有帮助,干杯。

If you run other web-applications on your apache-server it is likely that one of them ships with an .htaccess file that interferes with handling the /staus page (or whatever you named the page in the php-fpm pool-configuration).如果您在 apache-server 上运行其他 Web 应用程序,则其中一个可能附带一个.htaccess文件,该文件会干扰处理/staus页面(或您在 php-fpm 池配置中为该页面命名的任何内容)。

I recently came across that with a nextcloud instance.我最近在 nextcloud 实例中遇到了这个问题。 Within the nextcloud-(apache)-configuration whitelisting the URL and disabling the .htaccess -overrides for this path ( RewriteEngine Off ) made the page accessible in my case.在 nextcloud-(apache)-configuration 中,将 URL 列入白名单并禁用此路径的.htaccess -overrides ( RewriteEngine Off ) 使该页面在我的情况下可访问。 Be sure to replace the path to the socket with the correct path (this is stock Ubuntu 16.04 example).确保用正确的路径替换套接字的路径(这是 Ubuntu 16.04 的示例)。

<FilesMatch "^ping|status$">                                                       
  RewriteEngine Off
  SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"               
</FilesMatch>

Note As pointed out in the comments, the proper directive would likely be <Location "^ping|status$"> instead of <FilesMatch> .注意正如评论中所指出的,正确的指令可能是<Location "^ping|status$">而不是<FilesMatch>

The socket-path is defined at /etc/php/7.2/fpm/pool.d/www.conf ( listen = /run/php/php7.2-fpm.sock ) in default ubuntu version. socket-path 在默认 ubuntu 版本中定义在/etc/php/7.2/fpm/pool.d/www.conf ( listen = /run/php/php7.2-fpm.sock )。

If you're getting a permissions error, try adding如果您收到权限错误,请尝试添加

listen.mode = 0666

to /etc/php/7.0/fpm/pool.d/www.conf/etc/php/7.0/fpm/pool.d/www.conf

That was necessary for me to get the entire fastcgi stack with php-fpm running properly although I'm still not able to view the status page and am getting a 404 error when I try.尽管我仍然无法查看状态页面并且在我尝试时收到 404 错误,但这对我使整个 fastcgi 堆栈与 php-fpm 正常运行是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM