1. Caddy version (caddy version
):
v2.4.5 on Debian 10
2. How I run Caddy:
As a single systemd
service.
a. System environment:
b. Command:
/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
(run by systemd)
c. Service/unit/compose file:
File located in /lib/systemd/system/caddy.service
:
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
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:
Main caddyfile:
{
email pierstoval@gmail.com
}
{{main dedicated server domain name}} {
root * /var/www/html
file_server
}
import vhosts/*
The problem is related to one single vhost file:
demo.orbitale.io {
root * /var/www/demo.orbitale.io/www/
encode gzip
php_fastcgi unix//run/php/php8.0-fpm.sock {
resolve_root_symlink
}
file_server
tls {{tls custom email config}}
log {
output file {{log file path}} {
roll_size 512mb
roll_keep_for 720h
}
}
}
3. The problem I’m having:
When going to this website: https://demo.orbitale.io/faker_online/
Submitting the form should trigger an XHR Request to https://demo.orbitale.io/faker_online/fake/, but it returns a 404 not found.
4. Error messages and/or full log output:
Caddy’s log when curl
-ing to the /fake/
url of the above app:
{"level":"error","ts":1634500209.361947,"logger":"http.log.access.log4","msg":"handled request","request":{"remote_addr":"109.29.59.153:58600","proto":"HTTP/2.0","method":"POST","host":"demo.orbitale.io","uri":"/faker_online/fake/","headers":{"Content-Type":["application/x-www-form-urlencoded"],"Dnt":["1"],"Sec-Fetch-Site":["same-origin"],"Cache-Control":["no-cache"],"Accept-Language":["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"],"Referer":["https://demo.orbitale.io/faker_online/"],"Origin":["https://demo.orbitale.io"],"Content-Length":["66"],"Sec-Fetch-Dest":["empty"],"Pragma":["no-cache"],"Accept":["text/html"],"Accept-Encoding":["gzip, deflate, br"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"],"Sec-Fetch-Mode":["cors"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","proto_mutual":true,"server_name":"demo.orbitale.io"}},"common_log":"109.29.59.153 - - [17/Oct/2021:19:50:09 +0000] \"POST /faker_online/fake/ HTTP/2.0\" 404 0","user_id":"","duration":0.000339369,"size":0,"status":404,"resp_headers":{"Server":["Caddy"]}}
5. What I already tried:
I activated debug
in the Caddyfile
, and it allowed me to see that Caddy uses the file_server
handler and not the php_fastcgi
one:
oct. 17 19:50:58 piers caddy[21277]: {"level":"debug","ts":1634500258.6447387,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/var/www/demo.orbitale.io/www/","request_path":"/faker_online/fake/","result":"/var/www/demo.orbitale.io/www/faker_online/fake/"}
I tried adding the resolve_root_symlink
directive in the php_fastcgi
block, but it changed nothing.
I tried changing the PHP version from 8.0 to 7.4, nothing changed (I guess then it’s not a php-fpm issue).
I also tried removing the file_server
directive, and what happens is interesting:
The request to /fake/
now returns an HTTP 200, but … the Symfony app isn’t called. And I know it because according to the source code (you can see it here), it shouldn’t return an empty HTTP 200 Response. The reponse must at least contain Results:<br>
. Which isn’t the case here. That’s how I know the Symfony app isn’t even called.
EDIT: I also tried adding this to the vhost file:
php_fastcgi /faker_online unix//run/php/php8.0-fpm.sock {
root /var/www/demo.orbitale.io/repos/faker_online/public/
}
The idea was to create a custom php_fastcgi
with a matcher
that would help redefining the root
directive… But it didn’t work either.
6. Links to relevant resources:
It is worth noting that the app is under a symlink:
/var/www/demo.orbitale.io/www $ ls -Gg
total 0
lrwxrwxrwx 1 29 sept. 11 2019 faker_online -> ../repos/faker_online/public/
I have no idea on whether it can be a problem, nor how to fix it.
This server hosts several other PHP apps, including Symfony ones (like this one, which works fine, with the same Caddyfile config, the only difference is that the root
points to the {project path}/public
directory of the project, and no symlink is involved).