I’ve tried to create a simple test case.
v2.0 beta 9
/m/projects/site/project/web/test.php
(shows PHP Variables):
<?php phpinfo(32); ?>
The Caddyfile is below, with comments listing results of requesting this URL:
http://www.example.localhost/blog
http://www.example.localhost
tls off
root * /m/projects/site/project/web
# Only one of the three try_files uncommented at a time
try_files /test.php?p={path}&{query} # 404 status: 'File not found.'
try_files /test.php? # 404 status: 'File not found.'
try_files /test.php # shows PHP Variables page
reverse_proxy {
to unix//run/php/php7.3-fpm.sock
transport fastcgi {
split .php
}
}
Am I right in thinking that all three try_files
should show the test.php
PHP Variables page, as processed and output by PHP? Does adding the ?
to the filename result in Caddy looking for a file literally named test.php?
?
As an aside, I came across this while experimenting: when requesting http://www.example.localhost/?p=1
with try_files /test.php?
or try_files /test.php?p={path}&{query}
(but not with try_files /test.php
) uncommented I get the following:
Error
2019/11/18 10:34:34.672 INFO http.log.access received request {"request": {"method": "GET", "uri": "/?p=1", "proto": "HTTP/1.1", "remote_addr": "[::1]:42920", "host": "www.example.localhost", "headers": {"Pragma": ["no-cache"], "Cache-Control": ["no-cache"], "User-Agent": ["Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Upgrade-Insecure-Requests": ["1"], "Accept-Language": ["en-GB,en;q=0.5"], "Dnt": ["1"]}}, "common_log": "::1 - - [18/Nov/2019:11:34:34 +0100] \"GET /?p=1 HTTP/1.1\" 0 0", "latency": 0.000039485, "size": 0, "status": 0}
2019/11/18 11:34:34 http: panic serving [::1]:42920: runtime error: slice bounds out of range [:3] with length 1
goroutine 113 [running]:
net/http.(*conn).serve.func1(0xc000131220)
/usr/local/go/src/net/http/server.go:1767 +0x139
panic(0xd5a140, 0xc000274b00)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.buildEnv(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xdd180b,
0x10, ...)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:176 +0x196b
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.RoundTrip(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xdd180b, 0x10, ...)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:91 +0x7c
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).reverseProxy(0xc000276990, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1c00, 0xc0001dfdc0, 0xc000274ae0, 0x4, 0xc000274ae5, 0x18, 0x0, ...)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/reverseproxy/reverseproxy.go:391 +0x1f0
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).ServeHTTP(0xc000276990, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260, 0xe05a48, 0x0, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/reverseproxy/reverseproxy.go:288 +0xaf4
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0x0, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc00023fd80, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260,
0xc00023fd80)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/caddyhttp.go:532 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc0002813a0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260,
0xe05a48, 0xffffffffffffffff, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/subroute.go:71 +0x80
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0x152c4f0, 0xc0002da120)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc00023fd20, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xc00026ace8, 0xc000134ba0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/caddyhttp.go:532 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.VarsMiddleware.ServeHTTP(0xc0002b0b40, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260, 0xc00023fd20, 0x2, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/vars.go:48 +0x2c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0x0, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc00023fd40, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260,
0xc00023fd40)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/caddyhttp.go:532 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc000280fa0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260,
0xe05a48, 0xc000375420, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/subroute.go:71 +0x80
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0x0, 0x8)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc00023fc80, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0x203000,
0x203000)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/caddyhttp.go:532 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler(0xc00029e4e0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xf06260, 0xc00023fc80, 0x40caf8, 0x20)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/server.go:237 +0x9b
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).wrapPrimaryRoute.func1(0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xd12fa0, 0xc00023fca0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/server.go:213 +0x5a
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc00023fca0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00, 0xc00023fca0, 0xc00023fc80)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/caddyhttp.go:532 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).executeCompositeRoute(0xc00029e4e0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00,
0xc0002d8000, 0x1, 0x4, 0xc00027e690, 0x0)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/server.go:198 +0xff
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc00029e4e0, 0x7efbfd2300e8, 0xc0002ced80, 0xc0000f1b00)
/Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta9/modules/caddyhttp/server.go:135 +0x73f
net/http.serverHandler.ServeHTTP(0xc00016a380, 0xf159e0, 0xc00001c460, 0xc0000f1900)
/usr/local/go/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc000131220, 0xf186a0, 0xc0002cec40)
/usr/local/go/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2927 +0x38e
Git commit 9fe54e1c6025a45cdd531c093bb94d193a8b91a0
When compiling from source and trying again, I found that Caddy can’t connect to the PHP socket (it’s still there, and has permissions of 666
).
http://www.example.localhost/blog
:
2019/11/18 10:45:13.535 ERROR http.log.error dialing backend: dial unix /run/php/php7.3-fpm.sock:0: connect: no such file or directory {“request”: {“method”: “GET”, “uri”: “/blog”, “proto”: “HTTP/1.1”, “remote_addr”: “[::1]:43150”, “host”: “www.example.localhost”, “headers”: {“Accept-Language”: [“en-GB,en;q=0.5”], “Accept-Encoding”: [“gzip, deflate”], “Upgrade-Insecure-Requests”: [“1”], “Pragma”: [“no-cache”], “Cache-Control”: [“no-cache”], “User-Agent”: [“Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0”], “Accept”: [“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”], “Dnt”: [“1”], “Connection”: [“keep-alive”]}}, “status”: 502, “err_id”: “5hg5xcs0c”, “err_trace”: “reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:330)”}
A different error when requesting /?p=1
, which repeated several times for one request:
http://www.example.localhost/?p=1
:
Error
2019/11/18 11:40:58 http: panic serving [::1]:43056: runtime error: slice bounds out of range [:3] with length 1
goroutine 22 [running]:
net/http.(*conn).serve.func1(0xc0000f30e0)
/home/david/.asdf/installs/golang/1.13.4/go/src/net/http/server.go:1767 +0x139
panic(0xda8ca0, 0xc0002dc0c0)
/home/david/.asdf/installs/golang/1.13.4/go/src/runtime/panic.go:679 +0x1b2
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.buildEnv(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe24ecf, 0x10, ...)
/home/david/go/caddy/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:176 +0x196b
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.RoundTrip(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe24ecf, 0x10, ...)
/home/david/go/caddy/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:91 +0x7c
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).reverseProxy(0xc00020aaa0, 0xf74260, 0xc0002ec000, 0xc0002da300, 0xc000262600, 0xc0002210a0, 0x4, 0xc0002dc060, 0x1a, 0xc0002210a5, ...)
/home/david/go/caddy/modules/caddyhttp/reverseproxy/reverseproxy.go:409 +0x1f0
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).ServeHTTP(0xc00020aaa0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xe5ae98, 0x0, 0x0)
/home/david/go/caddy/modules/caddyhttp/reverseproxy/reverseproxy.go:314 +0xb30
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0xf74260, 0xc0002ec000, 0xc0002da200, 0x0, 0x0)
/home/david/go/caddy/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002f42c0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xc0002f42c0)
/home/david/go/caddy/modules/caddyhttp/caddyhttp.go:539 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc0002593e0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xe5ae98, 0xffffffffffffffff, 0x0)
/home/david/go/caddy/modules/caddyhttp/subroute.go:71 +0x80
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0xf74260, 0xc0002ec000, 0xc0002da200, 0x15c2cb0, 0xc00025fb00)
/home/david/go/caddy/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002f4260, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xc0002c81a8, 0xc00003ac60)
/home/david/go/caddy/modules/caddyhttp/caddyhttp.go:539 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.VarsMiddleware.ServeHTTP(0xc0002650b0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xc0002f4260, 0x2, 0x0)
/home/david/go/caddy/modules/caddyhttp/vars.go:48 +0x2c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0xf74260, 0xc0002ec000, 0xc0002da200, 0x0, 0x0)
/home/david/go/caddy/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002f4280, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xc0002f4280)
/home/david/go/caddy/modules/caddyhttp/caddyhttp.go:539 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Subroute).ServeHTTP(0xc000258fe0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xe5ae98, 0xc0002d1420, 0x0)
/home/david/go/caddy/modules/caddyhttp/subroute.go:71 +0x80
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1(0xf74260, 0xc0002ec000, 0xc0002da200, 0x0, 0x8)
/home/david/go/caddy/modules/caddyhttp/routes.go:151 +0x62
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002f41e0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0x203000, 0x203000)
/home/david/go/caddy/modules/caddyhttp/caddyhttp.go:539 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler(0xc0002665b0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xf640c0, 0xc0002f41e0, 0x40e568, 0x20)
/home/david/go/caddy/modules/caddyhttp/server.go:238 +0x9b
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).wrapPrimaryRoute.func1(0xf74260, 0xc0002ec000, 0xc0002da200, 0xd5f0e0, 0xc0002f4200)
/home/david/go/caddy/modules/caddyhttp/server.go:214 +0x5a
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002f4200, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xc0002f4200, 0xc0002f41e0)
/home/david/go/caddy/modules/caddyhttp/caddyhttp.go:539 +0x44
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).executeCompositeRoute(0xc0002665b0, 0xf74260, 0xc0002ec000, 0xc0002da200, 0xc00000c1e0, 0x1, 0x4, 0xc0002ba240, 0xc0002d42e8)
/home/david/go/caddy/modules/caddyhttp/server.go:199 +0xff
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0002665b0, 0xf74260, 0xc0002ec000, 0xc0002da200)
/home/david/go/caddy/modules/caddyhttp/server.go:136 +0x73d
net/http.serverHandler.ServeHTTP(0xc000178380, 0xf74260, 0xc0002ec000, 0xc0002da000)
/home/david/.asdf/installs/golang/1.13.4/go/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0000f30e0, 0xf77120, 0xc0002bc000)
/home/david/.asdf/installs/golang/1.13.4/go/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
/home/david/.asdf/installs/golang/1.13.4/go/src/net/http/server.go:2927 +0x38e