Skip to content

Commit

Permalink
Add resolve symlink feature in php_fastcgi
Browse files Browse the repository at this point in the history
  • Loading branch information
endelwar committed Jul 18, 2020
1 parent 246a31a commit b31dc03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
// root <path>
// split <at>
// env <key> <value>
// resolverootsymlink
// }
//
func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
Expand Down Expand Up @@ -67,6 +68,9 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
t.EnvVars[args[0]] = args[1]

case "resolverootsymlink":
t.ResolveRootSymlink = true

default:
return d.Errf("unrecognized subdirective %s", d.Val())
}
Expand Down Expand Up @@ -196,6 +200,14 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
return nil, dispenser.ArgErr()
}
indexFile = args[0]

case "resolverootsymlink":
args := dispenser.RemainingArgs()
dispenser.Delete()
for range args {
dispenser.Delete()
}
fcgiTransport.ResolveRootSymlink = true
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type Transport struct {
// that 404s if the fastcgi path info is not found.
SplitPath []string `json:"split_path,omitempty"`

// Resolve symlink in root path
ResolveRootSymlink bool `json:"resolve_root_symlink,omitempty"`

// Extra environment variables.
EnvVars map[string]string `json:"env,omitempty"`

Expand Down Expand Up @@ -179,6 +182,13 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
return nil, err
}

if t.ResolveRootSymlink {
root, err = filepath.EvalSymlinks(root)
if err != nil {
return nil, err
}
}

fpath := r.URL.Path

// split "actual path" from "path info" if configured
Expand Down

0 comments on commit b31dc03

Please sign in to comment.