What happened?
When using bind to a UNIX domain socket, $_SERVER['REMOTE_ADDR'] is @, which breaks many applications expecting an IP address in this field.
Steps to reproduce:
Caddyfile:
{
log {
output stderr
level DEBUG
}
auto_https off
}
http:// {
log {
output stderr
level DEBUG
}
bind unix//mnt/caddy.sock|0222
root /mnt
php_server
}
index.php:
<?=$_SERVER['REMOTE_ADDR'] . "\n";
Start FrankenPHP, e.g. with Podman (Docker should work too, or adapt bind and root paths in Caddyfile if using host build):
podman run -d --name frankenphp --rm -v "${PWD}":/mnt docker.io/dunglas/frankenphp:1.12-php8.4-trixie frankenphp run --config /mnt/Caddyfile
Request the socket:
curl --unix-socket caddy.sock http://localhost/
Response:
(To remove the container, run podman rm -f frankenphp)
This @ comes from Go's internals, see this issue for more information. In our case, request.RemoteAddr is @ here:
Proposed solution: for this special case, set remote address to 127.0.0.1 or ::1... But feels wrong to hardcode this value.
Alternative solution: don't bind to a UNIX domain socket with FrankenPHP...
Build Type
Docker (Debian Trixie)
Worker Mode
No
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
phpinfo() output
Relevant log output
Relevant log output
{"level":"debug","ts":1780220477.5129018,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"@","remote_port":"","client_ip":"@","proto":"HTTP/1.1","method":"GET","host":"localhost","uri":"/index.php","headers":{"User-Agent":["curl/8.20.0"],"Accept":["*/*"]}},"method":"GET","uri":"/index.php"}
{"level":"info","ts":1780220477.5133996,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"@","remote_port":"","client_ip":"@","proto":"HTTP/1.1","method":"GET","host":"localhost","uri":"/","headers":{"User-Agent":["curl/8.20.0"],"Accept":["*/*"]}},"bytes_read":0,"user_id":"","duration":0.00064167,"size":2,"status":200,"resp_headers":{"Server":["FrankenPHP Caddy"],"X-Powered-By":["PHP/8.4.21"],"Content-Type":["text/html; charset=UTF-8"]}}
What happened?
When using
bindto a UNIX domain socket,$_SERVER['REMOTE_ADDR']is@, which breaks many applications expecting an IP address in this field.Steps to reproduce:
Caddyfile:
{ log { output stderr level DEBUG } auto_https off } http:// { log { output stderr level DEBUG } bind unix//mnt/caddy.sock|0222 root /mnt php_server }index.php:
Start FrankenPHP, e.g. with Podman (Docker should work too, or adapt bind and root paths in Caddyfile if using host build):
podman run -d --name frankenphp --rm -v "${PWD}":/mnt docker.io/dunglas/frankenphp:1.12-php8.4-trixie frankenphp run --config /mnt/CaddyfileRequest the socket:
Response:
(To remove the container, run
podman rm -f frankenphp)This
@comes from Go's internals, see this issue for more information. In our case,request.RemoteAddris@here:frankenphp/cgi.go
Line 53 in 64bb386
Proposed solution: for this special case, set remote address to
127.0.0.1or::1... But feels wrong to hardcode this value.Alternative solution: don't bind to a UNIX domain socket with FrankenPHP...
Build Type
Docker (Debian Trixie)
Worker Mode
No
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
phpinfo() output
Relevant log output
Relevant log output
{"level":"debug","ts":1780220477.5129018,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"@","remote_port":"","client_ip":"@","proto":"HTTP/1.1","method":"GET","host":"localhost","uri":"/index.php","headers":{"User-Agent":["curl/8.20.0"],"Accept":["*/*"]}},"method":"GET","uri":"/index.php"} {"level":"info","ts":1780220477.5133996,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"@","remote_port":"","client_ip":"@","proto":"HTTP/1.1","method":"GET","host":"localhost","uri":"/","headers":{"User-Agent":["curl/8.20.0"],"Accept":["*/*"]}},"bytes_read":0,"user_id":"","duration":0.00064167,"size":2,"status":200,"resp_headers":{"Server":["FrankenPHP Caddy"],"X-Powered-By":["PHP/8.4.21"],"Content-Type":["text/html; charset=UTF-8"]}}