1. The problem I’m having:
I’m on week 1 of caddy so please forgive me if this is obvious.
I have a handful of PHP files that comprise a small API. Params are passed on the URL, due to some old software I can’t change.
$ curl -vL https://api.gingerbeardman.com/v1/posts/add?url=https://www.example.com&description=Example
But the URL params are being stripped by the time I check in the PHP, both the following are blank:
print_r($_SERVER['QUERY_STRING'], true);
print_r($_GET, true);
Thanks to MaxGhost on Reddit, I see that Caddy sets query. But as we can see below from logs they disappear.
I think I need to keep them somehow during the rewrite? I’m not doing any of that right now.
2. Error messages and/or full log output:
Nov 27 10:20:48 phoenix caddy[2443]: {"level":"debug","ts":1732702848.8315847,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"144.24.224.205","remote_port":"60016","client_ip":"144.24.224.205","proto":"HTTP/2.0","method":"GET","host":"api.gingerbeardman.com","uri":"/v1/posts/add/","headers":{"User-Agent":["curl/7.61.1"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"api.gingerbeardman.com"}},"method":"GET","uri":"/v1/posts/add/index.php"}
Nov 27 10:20:48 phoenix caddy[2443]: {"level":"debug","ts":1732702848.8316858,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_ip":"144.24.224.205","remote_port":"60016","client_ip":"144.24.224.205","proto":"HTTP/2.0","method":"GET","host":"api.gingerbeardman.com","uri":"/v1/posts/add/index.php","headers":{"X-Forwarded-Host":["api.gingerbeardman.com"],"User-Agent":["curl/7.61.1"],"Accept":["*/*"],"X-Forwarded-For":["144.24.224.205"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"api.gingerbeardman.com"}},"env":{"REMOTE_ADDR":"144.24.224.205","HTTP_HOST":"api.gingerbeardman.com","HTTP_USER_AGENT":"curl/7.61.1","REMOTE_PORT":"60016","DOCUMENT_URI":"/v1/posts/add/index.php","HTTP_X_FORWARDED_HOST":"api.gingerbeardman.com","REQUEST_URI":"/v1/posts/add/","HTTPS":"on","REMOTE_HOST":"144.24.224.205","REQUEST_METHOD":"GET","DOCUMENT_ROOT":"/var/www/api.gingerbeardman.com/htdocs","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","AUTH_TYPE":"","REQUEST_SCHEME":"https","SERVER_PROTOCOL":"HTTP/2.0","HTTP_X_FORWARDED_PROTO":"https","CONTENT_LENGTH":"","CONTENT_TYPE":"","SERVER_PORT":"443","HTTP_X_FORWARDED_FOR":"144.24.224.205","PATH_INFO":"","SCRIPT_NAME":"/v1/posts/add/index.php","SSL_PROTOCOL":"TLSv1.3","HTTP_ACCEPT":"*/*","REMOTE_IDENT":"","QUERY_STRING":"","REMOTE_USER":"","SCRIPT_FILENAME":"/var/www/api.gingerbeardman.com/htdocs/v1/posts/add/index.php","GATEWAY_INTERFACE":"CGI/1.1","SERVER_NAME":"api.gingerbeardman.com","SERVER_SOFTWARE":"Caddy/v2.8.4"},"dial":"/run/php-fpm/www.sock","env":{"SERVER_NAME":"api.gingerbeardman.com","SERVER_SOFTWARE":"Caddy/v2.8.4","SCRIPT_FILENAME":"/var/www/api.gingerbeardman.com/htdocs/v1/posts/add/index.php","GATEWAY_INTERFACE":"CGI/1.1","HTTP_HOST":"api.gingerbeardman.com","HTTP_USER_AGENT":"curl/7.61.1","REMOTE_ADDR":"144.24.224.205","DOCUMENT_URI":"/v1/posts/add/index.php","HTTP_X_FORWARDED_HOST":"api.gingerbeardman.com","REMOTE_PORT":"60016","REQUEST_METHOD":"GET","DOCUMENT_ROOT":"/var/www/api.gingerbeardman.com/htdocs","REQUEST_URI":"/v1/posts/add/","HTTPS":"on","REMOTE_HOST":"144.24.224.205","REQUEST_SCHEME":"https","SERVER_PROTOCOL":"HTTP/2.0","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","AUTH_TYPE":"","CONTENT_TYPE":"","SERVER_PORT":"443","HTTP_X_FORWARDED_PROTO":"https","CONTENT_LENGTH":"","SCRIPT_NAME":"/v1/posts/add/index.php","SSL_PROTOCOL":"TLSv1.3","HTTP_X_FORWARDED_FOR":"144.24.224.205","PATH_INFO":"","QUERY_STRING":"","REMOTE_USER":"","HTTP_ACCEPT":"*/*","REMOTE_IDENT":""},"request":{"remote_ip":"144.24.224.205","remote_port":"60016","client_ip":"144.24.224.205","proto":"HTTP/2.0","method":"GET","host":"api.gingerbeardman.com","uri":"/v1/posts/add/index.php","headers":{"Accept":["*/*"],"X-Forwarded-For":["144.24.224.205"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["api.gingerbeardman.com"],"User-Agent":["curl/7.61.1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"api.gingerbeardman.com"}}}
Nov 27 10:20:49 phoenix caddy[2443]: {"level":"debug","ts":1732702849.244736,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"unix//run/php-fpm/www.sock","duration":0.413083204,"request":{"remote_ip":"144.24.224.205","remote_port":"60016","client_ip":"144.24.224.205","proto":"HTTP/2.0","method":"GET","host":"api.gingerbeardman.com","uri":"/v1/posts/add/index.php","headers":{"User-Agent":["curl/7.61.1"],"Accept":["*/*"],"X-Forwarded-For":["144.24.224.205"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["api.gingerbeardman.com"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"api.gingerbeardman.com"}},"headers":{"X-Powered-By":["PHP/7.4.33"],"Content-Type":["text/xml; charset=utf-8"]},"status":200}
3. Caddy version:
2.8.4
4. How I installed and ran Caddy:
dnf install caddy
a. System environment:
Oracle Linux 8 (RHEL8)
b. Command:
systemctl start caddy
c. Service/unit/compose file:
n/a
d. My complete Caddy config:
api.gingerbeardman.com {
tls email@example.com
root * /var/www/api.gingerbeardman.com/htdocs
php_fastcgi unix//run/php-fpm/www.sock
log {
output file /var/log/caddy/api.access.log
}
}