Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
fastcgi: Add resolve_root_symlink (#3587)
Manuel Dalla Lana committed
Jul 20, 2020 at 20:16 UTC
2ae8c119279826ef81223e3b2155a08779f3ee8b
2 files changed
+27
modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+12
@@ -39,6 +39,7 @@ func init() {
39
// root <path>
40
// split <at>
41
// env <key> <value>
42
+// resolve_root_symlink
43
// }
44
//
45
func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
@@ -67,6 +68,9 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
68
}
69
t.EnvVars[args[0]] = args[1]
70
71
+ case "resolve_root_symlink":
72
+ t.ResolveRootSymlink = true
73
+
74
default:
75
return d.Errf("unrecognized subdirective %s", d.Val())
76
}
@@ -196,6 +200,14 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
200
return nil, dispenser.ArgErr()
201
}
202
indexFile = args[0]
203
+
204
+ case "resolve_root_symlink":
205
+ args := dispenser.RemainingArgs()
206
+ dispenser.Delete()
207
+ for range args {
208
+ dispenser.Delete()
209
+ }
210
+ fcgiTransport.ResolveRootSymlink = true
211
}
212
}
213
}
modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
+15
@@ -54,6 +54,14 @@ type Transport struct {
54
// that 404s if the fastcgi path info is not found.
55
SplitPath []string `json:"split_path,omitempty"`
56
57
+ // Path declared as root directory will be resolved to its absolute value
58
+ // after the evaluation of any symbolic links.
59
+ // Due to the nature of PHP opcache, root directory path is cached: when
60
+ // using a symlinked directory as root this could generate errors when
61
+ // symlink is changed without php-fpm being restarted; enabling this
62
+ // directive will set $_SERVER['DOCUMENT_ROOT'] to the real directory path.
63
+ ResolveRootSymlink bool `json:"resolve_root_symlink,omitempty"`
64
+
65
// Extra environment variables.
66
EnvVars map[string]string `json:"env,omitempty"`
67
@@ -179,6 +187,13 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
187
return nil, err
188
}
189
190
+ if t.ResolveRootSymlink {
191
+ root, err = filepath.EvalSymlinks(root)
192
+ if err != nil {
193
+ return nil, err
194
+ }
195
+ }
196
+
197
fpath := r.URL.Path
198
199
// split "actual path" from "path info" if configured