@marcel91200 / caddy Mirror · read-only / commits / b1480eb5
Fork 0

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: Fix php_fastcgi matcher regression (#3512)

Francis Lavoie committed Jun 22, 2020 at 13:45 UTC b1480eb52f8e3dd621798e2b74b4e3e47bacc9f5
2 files changed +122 -10
caddytest/integration/caddyfile_adapt/php_fastcgi_matcher.txt new
+112
@@ -0,0 +1,112 @@
1 +:8884
2 +
3 +@api host example.com
4 +php_fastcgi @api localhost:9000
5 +----------
6 +{
7 + "apps": {
8 + "http": {
9 + "servers": {
10 + "srv0": {
11 + "listen": [
12 + ":8884"
13 + ],
14 + "routes": [
15 + {
16 + "match": [
17 + {
18 + "host": [
19 + "example.com"
20 + ]
21 + }
22 + ],
23 + "handle": [
24 + {
25 + "handler": "subroute",
26 + "routes": [
27 + {
28 + "handle": [
29 + {
30 + "handler": "static_response",
31 + "headers": {
32 + "Location": [
33 + "{http.request.uri.path}/"
34 + ]
35 + },
36 + "status_code": 308
37 + }
38 + ],
39 + "match": [
40 + {
41 + "file": {
42 + "try_files": [
43 + "{http.request.uri.path}/index.php"
44 + ]
45 + },
46 + "not": [
47 + {
48 + "path": [
49 + "*/"
50 + ]
51 + }
52 + ]
53 + }
54 + ]
55 + },
56 + {
57 + "handle": [
58 + {
59 + "handler": "rewrite",
60 + "uri": "{http.matchers.file.relative}"
61 + }
62 + ],
63 + "match": [
64 + {
65 + "file": {
66 + "split_path": [
67 + ".php"
68 + ],
69 + "try_files": [
70 + "{http.request.uri.path}",
71 + "{http.request.uri.path}/index.php",
72 + "index.php"
73 + ]
74 + }
75 + }
76 + ]
77 + },
78 + {
79 + "handle": [
80 + {
81 + "handler": "reverse_proxy",
82 + "transport": {
83 + "protocol": "fastcgi",
84 + "split_path": [
85 + ".php"
86 + ]
87 + },
88 + "upstreams": [
89 + {
90 + "dial": "localhost:9000"
91 + }
92 + ]
93 + }
94 + ],
95 + "match": [
96 + {
97 + "path": [
98 + "*.php"
99 + ]
100 + }
101 + ]
102 + }
103 + ]
104 + }
105 + ]
106 + }
107 + ]
108 + }
109 + }
110 + }
111 + }
112 +}
\ No newline at end of file
modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+10 -10
@@ -132,6 +132,16 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
132 // set the default index file for the try_files rewrites
133 indexFile := "index.php"
134
135 + // if the user specified a matcher token, use that
136 + // matcher in a route that wraps both of our routes;
137 + // either way, strip the matcher token and pass
138 + // the remaining tokens to the unmarshaler so that
139 + // we can gain the rest of the reverse_proxy syntax
140 + userMatcherSet, err := h.ExtractMatcherSet()
141 + if err != nil {
142 + return nil, err
143 + }
144 +
145 // make a new dispenser from the remaining tokens so that we
146 // can reset the dispenser back to this point for the
147 // reverse_proxy unmarshaler to read from it as well
@@ -252,16 +262,6 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
262 "path": h.JSON(pathList),
263 }
264
255 - // if the user specified a matcher token, use that
256 - // matcher in a route that wraps both of our routes;
257 - // either way, strip the matcher token and pass
258 - // the remaining tokens to the unmarshaler so that
259 - // we can gain the rest of the reverse_proxy syntax
260 - userMatcherSet, err := h.ExtractMatcherSet()
261 - if err != nil {
262 - return nil, err
263 - }
264 -
265 // create the reverse proxy handler which uses our FastCGI transport
266 rpHandler := &reverseproxy.Handler{
267 TransportRaw: caddyconfig.JSONModuleObject(fcgiTransport, "protocol", "fastcgi", nil),