PHP FPM status page in Caddy 2

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

a. System environment:

Ubuntu 20.04, default systemd config of Caddy when installing through apt

b. Command:

sudo service caddy start

c. Service/unit/compose file:

# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

:8888 {
        php_fastcgi /fpm_status unix//var/run/php/php7.4-fpm.sock {
                env SCRIPT_NAME /fpm_status
        }
}

3. The problem I’m having:

I’m trying to get the PHP FPM status page to load, but can’t quite work it out. Searching here for past questions, they’re all referencing Caddy 1 (Enable php-fpm status page or [solved] Php-fpm status page won't load) (which I hadn’t ever used), and can’t quite work out how to adjust it to work with Caddy 2.

I have this Nginx snippet that works:

server {
  listen localhost:8888;
  server_name 127.0.0.1 localhost;

  location ~ ^/(fpm_status)$ {
    access_log off;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    allow 127.0.0.1;
    deny all;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  }
}

But can’t quite work out how to translate it :slightly_frowning_face:

4. Error messages and/or full log output:

Nothing in the logs that I can see, errors or not

5. What I already tried:

I’ve tried playing around with the path, env variables, all kinds of random changes, but I always just get a happy 200 from Caddy :confused:

6. Links to relevant resources:

Thanks!

Hmm. I’ve never tried to serve the FPM status page so I’m not certain how that should work.

What I can say though, is that the php_fastcgi directive is meant as a shortcut, and has a bunch of built-in redirects which may mess with whatever you’d need for it to work. See the expanded form:

So maybe what you need is to use the reverse_proxy directive with the fastcgi transport directly:

reverse_proxy unix//var/run/php/php7.4-fpm.sock {
	transport fastcgi {
		env SCRIPT_NAME /fpm_status
	}
}
2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.