Skip to content

Update Caddy dependency #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -2,4 +2,4 @@ module github.com/caddyserver/nginx-adapter

go 1.13

require github.com/caddyserver/caddy/v2 v2.0.0-beta.13.0.20200208193637-98bbc54fdcd0
require github.com/caddyserver/caddy/v2 v2.0.0-beta.20
727 changes: 681 additions & 46 deletions go.sum

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions processors.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
)

var splitPathInfoExtension = regexp.MustCompile(`(\.[[:alnum:]]+)`)

func processAllow(dir Directive) map[string]caddyhttp.RequestMatcher {
var reqMatcher caddyhttp.RequestMatcher
var key string
@@ -235,15 +237,20 @@ func processFastCGIPass(dirs []Directive) (*caddyhttp.Subroute, []caddyconfig.Wa
HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(rewriteHandler, "handler", "rewrite", nil)},
}

extension := ".php"
if v, ok := getDirective(dirs, "fastcgi_split_path_info"); ok {
extension = v.Param(1)
extension := []string{".php"}

// The fastcgi_split_path_info directive takes a regexp with two capture groups,
// the first capture group points to the script file name and the second is for path info.
// For example, the regexp for php could be `^(.+.php)(/.*)$`. Caddy splits over the extension. So splitPathInfoExtension
// finds the extension in the provided input, extract it, and use it for the config.
if v, ok := getDirective(dirs, "fastcgi_split_path_info"); ok && splitPathInfoExtension.MatchString(v.Param(1)) {
extension[0] = splitPathInfoExtension.FindStringSubmatch(v.Param(1))[1]
}

// route to actually reverse proxy requests to PHP files;
// match only requests that are for PHP files
rpMatcherSet := caddy.ModuleMap{
"path": caddyconfig.JSON([]string{"*" + extension}, &warns),
"path": caddyconfig.JSON([]string{"*" + extension[0]}, &warns),
}

// set up the transport for FastCGI, and specifically PHP