The README states:
The current working directory will be the same as Caddy itself.
But when testing, the CGI process's CWD is set to the directory containing the CGI script, not to Caddy's CWD.
Steps to reproduce
- Create this directory structure:
/tmp/cgi-bug-report/
├── Caddyfile
└── subdir/
└── test.sh
- Create
/tmp/cgi-bug-report/subdir/test.sh:
#!/bin/sh
printf "Content-type: text/plain\r\n\r\n"
printf "CWD: %s\n" "$(pwd)"
chmod +x /tmp/cgi-bug-report/subdir/test.sh
- Create
/tmp/cgi-bug-report/Caddyfile:
{
debug
auto_https disable_redirects
}
http://localhost:8080 {
cgi / subdir/test.sh
}
- Run caddy from
/tmp/cgi-bug-report:
cd /tmp/cgi-bug-report && caddy run --config Caddyfile
curl http://localhost:8080/
Expected output
CWD should be /tmp/cgi-bug-report (Caddy's CWD).
Actual output
CWD: /tmp/cgi-bug-report/subdir
CWD is the script's directory, not Caddy's CWD.
Discussion
Adding dir . to the cgi block fixes it:
cgi / subdir/test.sh {
dir .
}
Then output is:
I suggest that we fix the documentation to say that the cwd defaults to the script's directory, and that dir argument is relative to the cwd that caddy was started from.
Environment
- caddy-cgi v2.2.7
- Caddy v2.x
- Go 1.21+
The README states:
But when testing, the CGI process's CWD is set to the directory containing the CGI script, not to Caddy's CWD.
Steps to reproduce
/tmp/cgi-bug-report/subdir/test.sh:/tmp/cgi-bug-report/Caddyfile:/tmp/cgi-bug-report:curl http://localhost:8080/Expected output
CWD should be
/tmp/cgi-bug-report(Caddy's CWD).Actual output
CWD is the script's directory, not Caddy's CWD.
Discussion
Adding
dir .to the cgi block fixes it:Then output is:
I suggest that we fix the documentation to say that the cwd defaults to the script's directory, and that
dirargument is relative to the cwd that caddy was started from.Environment