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, 04:00 UTC
fastcgi: Fix Caddyfile parsing when `handle_response` is used (#4342)
Francis Lavoie committed
Sep 11, 2021 at 16:12 UTC
a779e1b38390205e8286a0578042646d858039a5
2 files changed
+146
-1
caddytest/integration/caddyfile_adapt/php_fastcgi_handle_response.txt
new
+145
@@ -0,0 +1,145 @@
1
+:8881 {
2
+ php_fastcgi app:9000 {
3
+ env FOO bar
4
+
5
+ @error status 4xx
6
+ handle_response @error {
7
+ root * /errors
8
+ rewrite * /{http.reverse_proxy.status_code}.html
9
+ file_server
10
+ }
11
+ }
12
+}
13
+----------
14
+{
15
+ "apps": {
16
+ "http": {
17
+ "servers": {
18
+ "srv0": {
19
+ "listen": [
20
+ ":8881"
21
+ ],
22
+ "routes": [
23
+ {
24
+ "match": [
25
+ {
26
+ "file": {
27
+ "try_files": [
28
+ "{http.request.uri.path}/index.php"
29
+ ]
30
+ },
31
+ "not": [
32
+ {
33
+ "path": [
34
+ "*/"
35
+ ]
36
+ }
37
+ ]
38
+ }
39
+ ],
40
+ "handle": [
41
+ {
42
+ "handler": "static_response",
43
+ "headers": {
44
+ "Location": [
45
+ "{http.request.uri.path}/"
46
+ ]
47
+ },
48
+ "status_code": 308
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "match": [
54
+ {
55
+ "file": {
56
+ "try_files": [
57
+ "{http.request.uri.path}",
58
+ "{http.request.uri.path}/index.php",
59
+ "index.php"
60
+ ],
61
+ "split_path": [
62
+ ".php"
63
+ ]
64
+ }
65
+ }
66
+ ],
67
+ "handle": [
68
+ {
69
+ "handler": "rewrite",
70
+ "uri": "{http.matchers.file.relative}"
71
+ }
72
+ ]
73
+ },
74
+ {
75
+ "match": [
76
+ {
77
+ "path": [
78
+ "*.php"
79
+ ]
80
+ }
81
+ ],
82
+ "handle": [
83
+ {
84
+ "handle_response": [
85
+ {
86
+ "match": {
87
+ "status_code": [
88
+ 4
89
+ ]
90
+ },
91
+ "routes": [
92
+ {
93
+ "handle": [
94
+ {
95
+ "handler": "vars",
96
+ "root": "/errors"
97
+ }
98
+ ]
99
+ },
100
+ {
101
+ "group": "group0",
102
+ "handle": [
103
+ {
104
+ "handler": "rewrite",
105
+ "uri": "/{http.reverse_proxy.status_code}.html"
106
+ }
107
+ ]
108
+ },
109
+ {
110
+ "handle": [
111
+ {
112
+ "handler": "file_server",
113
+ "hide": [
114
+ "./Caddyfile"
115
+ ]
116
+ }
117
+ ]
118
+ }
119
+ ]
120
+ }
121
+ ],
122
+ "handler": "reverse_proxy",
123
+ "transport": {
124
+ "env": {
125
+ "FOO": "bar"
126
+ },
127
+ "protocol": "fastcgi",
128
+ "split_path": [
129
+ ".php"
130
+ ]
131
+ },
132
+ "upstreams": [
133
+ {
134
+ "dial": "app:9000"
135
+ }
136
+ ]
137
+ }
138
+ ]
139
+ }
140
+ ]
141
+ }
142
+ }
143
+ }
144
+ }
145
+}
\ No newline at end of file
modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+1
-1
@@ -192,7 +192,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
192
// NOTE: we delete the tokens as we go so that the reverse_proxy
193
// unmarshal doesn't see these subdirectives which it cannot handle
194
for dispenser.Next() {
195
- for dispenser.NextBlock(0) {
195
+ for dispenser.NextBlock(0) && dispenser.Nesting() == 1 {
196
switch dispenser.Val() {
197
case "root":
198
if !dispenser.NextArg() {