mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-01 04:22:36 +08:00 
			
		
		
		
	fastcgi: Fix php_fastcgi matcher regression (#3512)
This commit is contained in:
		
							
								
								
									
										112
									
								
								caddytest/integration/caddyfile_adapt/php_fastcgi_matcher.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								caddytest/integration/caddyfile_adapt/php_fastcgi_matcher.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,112 @@ | ||||
| :8884 | ||||
|  | ||||
| @api host example.com | ||||
| php_fastcgi @api localhost:9000 | ||||
| ---------- | ||||
| { | ||||
| 	"apps": { | ||||
| 		"http": { | ||||
| 			"servers": { | ||||
| 				"srv0": { | ||||
| 					"listen": [ | ||||
| 						":8884" | ||||
| 					], | ||||
| 					"routes": [ | ||||
| 						{ | ||||
| 							"match": [ | ||||
| 								{ | ||||
| 									"host": [ | ||||
| 										"example.com" | ||||
| 									] | ||||
| 								} | ||||
| 							], | ||||
| 							"handle": [ | ||||
| 								{ | ||||
| 									"handler": "subroute", | ||||
| 									"routes": [ | ||||
| 										{ | ||||
| 											"handle": [ | ||||
| 												{ | ||||
| 													"handler": "static_response", | ||||
| 													"headers": { | ||||
| 														"Location": [ | ||||
| 															"{http.request.uri.path}/" | ||||
| 														] | ||||
| 													}, | ||||
| 													"status_code": 308 | ||||
| 												} | ||||
| 											], | ||||
| 											"match": [ | ||||
| 												{ | ||||
| 													"file": { | ||||
| 														"try_files": [ | ||||
| 															"{http.request.uri.path}/index.php" | ||||
| 														] | ||||
| 													}, | ||||
| 													"not": [ | ||||
| 														{ | ||||
| 															"path": [ | ||||
| 																"*/" | ||||
| 															] | ||||
| 														} | ||||
| 													] | ||||
| 												} | ||||
| 											] | ||||
| 										}, | ||||
| 										{ | ||||
| 											"handle": [ | ||||
| 												{ | ||||
| 													"handler": "rewrite", | ||||
| 													"uri": "{http.matchers.file.relative}" | ||||
| 												} | ||||
| 											], | ||||
| 											"match": [ | ||||
| 												{ | ||||
| 													"file": { | ||||
| 														"split_path": [ | ||||
| 															".php" | ||||
| 														], | ||||
| 														"try_files": [ | ||||
| 															"{http.request.uri.path}", | ||||
| 															"{http.request.uri.path}/index.php", | ||||
| 															"index.php" | ||||
| 														] | ||||
| 													} | ||||
| 												} | ||||
| 											] | ||||
| 										}, | ||||
| 										{ | ||||
| 											"handle": [ | ||||
| 												{ | ||||
| 													"handler": "reverse_proxy", | ||||
| 													"transport": { | ||||
| 														"protocol": "fastcgi", | ||||
| 														"split_path": [ | ||||
| 															".php" | ||||
| 														] | ||||
| 													}, | ||||
| 													"upstreams": [ | ||||
| 														{ | ||||
| 															"dial": "localhost:9000" | ||||
| 														} | ||||
| 													] | ||||
| 												} | ||||
| 											], | ||||
| 											"match": [ | ||||
| 												{ | ||||
| 													"path": [ | ||||
| 														"*.php" | ||||
| 													] | ||||
| 												} | ||||
| 											] | ||||
| 										} | ||||
| 									] | ||||
| 								} | ||||
| 							] | ||||
| 						} | ||||
| 					] | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -132,6 +132,16 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error | ||||
| 	// set the default index file for the try_files rewrites | ||||
| 	indexFile := "index.php" | ||||
|  | ||||
| 	// 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 | ||||
| 	// the remaining tokens to the unmarshaler so that | ||||
| 	// we can gain the rest of the reverse_proxy syntax | ||||
| 	userMatcherSet, err := h.ExtractMatcherSet() | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// make a new dispenser from the remaining tokens so that we | ||||
| 	// can reset the dispenser back to this point for the | ||||
| 	// reverse_proxy unmarshaler to read from it as well | ||||
| @ -252,16 +262,6 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error | ||||
| 		"path": h.JSON(pathList), | ||||
| 	} | ||||
|  | ||||
| 	// 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 | ||||
| 	// the remaining tokens to the unmarshaler so that | ||||
| 	// we can gain the rest of the reverse_proxy syntax | ||||
| 	userMatcherSet, err := h.ExtractMatcherSet() | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// create the reverse proxy handler which uses our FastCGI transport | ||||
| 	rpHandler := &reverseproxy.Handler{ | ||||
| 		TransportRaw: caddyconfig.JSONModuleObject(fcgiTransport, "protocol", "fastcgi", nil), | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Francis Lavoie
					Francis Lavoie