Clashes with Caddy Admin API when Server block is localhost as well

When I am trying to access the Caddy API it seems to serve my Franken PHP application from the php_server line which is within a server block for localhost.

I changed the global config in realtime and adjusted the port, then set it back again to 2019, then the API was responding… bug or implementation issue?

I could adjust the server block that is configured on localhost too, add a matcher to prevent the reverse proxy serving, but I’m not sure this feels totally right. Otherwise I could specify localhost ports explicitly… I’m serving on localhost because it is within docker/kubernetes.

I’d be interested in the expected behaviour of if there is something I can put at the top of the server block to check for the port with a matcher and then skip the rest and serve the admin API.

What’s the config you ran? That seems like an issue in FrankenPHP, though

How can we reproduce the behavior?

Hi guys, sorry these reply notifications went to my junk.

The project is here:

The Caddyfile is here:

And you should be able to reproduce by running docker compose up php - then try a curl command to port 2019. It seemed intermittent. But when I changed the Caddyfile once the application was running, changed the admin port away from 2019 and then back again it started working.

Any environment configs are in compose:
Namely the server name for the block which I don’t think is changed anywhere else:

I don’t think you will need the override file. I just adjusted it so 2019 is exposed to the local machine by default too.

In the dockerfile the custom build is here:

I’ve had quite a few things on so if you’d like to leave it with me to test and re-test later to try and find a consistent reproduction please do let me know.

I guess my first question was is this actually a bug or is there a known way to prevent a server block being run before Caddy will run the admin on 2019, and should this config for the server block be responding to port 2019 if the name localhost is being used without additional ports or should it just be listening to 80 and 443? With this information, I could be able to do more digging.

By the way, I’m versioning Souin only because the recent patch removed the endpoint without going via Caddy API/Admin port. And this is why I discovered the issues I was having.