summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-09-17 10:23:06 -0400
committerGitHub <noreply@github.com>2021-09-17 08:23:06 -0600
commit3f2c3ecf85b590473030b21fd2b5fc9c8ef88744 (patch)
tree829aef7065e3b8041319d2ea02752727bb8be48a /modules/caddyhttp/reverseproxy
parent907e2d8d3a8ebaf14aa99939c493e56645bc2089 (diff)
fastcgi: Implement `try_files` override in Caddyfile directive (#4347)
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go42
1 files changed, 31 insertions, 11 deletions
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
index da1c92d..1b4cecf 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
@@ -124,21 +124,22 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
//
// is equivalent to a route consisting of:
//
+// # Add trailing slash for directory requests
// @canonicalPath {
-// file {
-// try_files {path}/index.php
-// }
-// not {
-// path */
-// }
+// file {path}/index.php
+// not path */
// }
// redir @canonicalPath {path}/ 308
//
-// try_files {path} {path}/index.php index.php
-//
-// @phpFiles {
-// path *.php
+// # If the requested file does not exist, try index files
+// @indexFiles file {
+// try_files {path} {path}/index.php index.php
+// split_path .php
// }
+// rewrite @indexFiles {http.matchers.file.relative}
+//
+// # Proxy PHP files to the FastCGI responder
+// @phpFiles path *.php
// reverse_proxy @phpFiles localhost:7777 {
// transport fastcgi {
// split .php
@@ -172,6 +173,9 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
// set the default index file for the try_files rewrites
indexFile := "index.php"
+ // set up for explicitly overriding try_files
+ tryFiles := []string{}
+
// if the user specified a matcher token, use that
// matcher in a route that wraps both of our routes;
// either way, strip the matcher token and pass
@@ -237,6 +241,17 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
}
indexFile = args[0]
+ case "try_files":
+ args := dispenser.RemainingArgs()
+ dispenser.Delete()
+ for range args {
+ dispenser.Delete()
+ }
+ if len(args) < 1 {
+ return nil, dispenser.ArgErr()
+ }
+ tryFiles = args
+
case "resolve_root_symlink":
args := dispenser.RemainingArgs()
dispenser.Delete()
@@ -318,10 +333,15 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(redirHandler, "handler", "static_response", nil)},
}
+ // if tryFiles wasn't overridden, use a reasonable default
+ if len(tryFiles) == 0 {
+ tryFiles = []string{"{http.request.uri.path}", "{http.request.uri.path}/" + indexFile, indexFile}
+ }
+
// route to rewrite to PHP index file
rewriteMatcherSet := caddy.ModuleMap{
"file": h.JSON(fileserver.MatchFile{
- TryFiles: []string{"{http.request.uri.path}", "{http.request.uri.path}/" + indexFile, indexFile},
+ TryFiles: tryFiles,
SplitPath: extensions,
}),
}