commit
3d681cda78
2 changed files with 31 additions and 18 deletions
|
@ -205,7 +205,13 @@ func buildLocation(input interface{}) string {
|
||||||
if path == slash {
|
if path == slash {
|
||||||
return fmt.Sprintf("~* %s", path)
|
return fmt.Sprintf("~* %s", path)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("~* ^%s", path)
|
// baseuri regex will parse basename from the given location
|
||||||
|
baseuri := `(?<baseuri>.*)`
|
||||||
|
if !strings.HasSuffix(path, slash) {
|
||||||
|
// Not treat the slash after "location path" as a part of baseuri
|
||||||
|
baseuri = fmt.Sprintf(`\/?%s`, baseuri)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`~* ^%s%s`, path, baseuri)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
@ -273,13 +279,10 @@ func buildProxyPass(b interface{}, loc interface{}) string {
|
||||||
if len(location.Redirect.Target) > 0 {
|
if len(location.Redirect.Target) > 0 {
|
||||||
abu := ""
|
abu := ""
|
||||||
if location.Redirect.AddBaseURL {
|
if location.Redirect.AddBaseURL {
|
||||||
bPath := location.Redirect.Target
|
// path has a slash suffix, so that it can be connected with baseuri directly
|
||||||
if !strings.HasSuffix(bPath, slash) {
|
bPath := fmt.Sprintf("%s%s", path, "$baseuri")
|
||||||
bPath = fmt.Sprintf("%s/", bPath)
|
abu = fmt.Sprintf(`subs_filter '<head(.*)>' '<head$1><base href="$scheme://$http_host%v">' r;
|
||||||
}
|
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$http_host%v">' r;
|
||||||
|
|
||||||
abu = fmt.Sprintf(`subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name%v">' r;
|
|
||||||
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name%v">' r;
|
|
||||||
`, bPath, bPath)
|
`, bPath, bPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,33 +45,43 @@ var (
|
||||||
rewrite /(.*) /jenkins/$1 break;
|
rewrite /(.*) /jenkins/$1 break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
`, false},
|
`, false},
|
||||||
"redirect /something to /": {"/something", "/", "~* ^/something", `
|
"redirect /something to /": {"/something", "/", `~* ^/something\/?(?<baseuri>.*)`, `
|
||||||
rewrite /something/(.*) /$1 break;
|
rewrite /something/(.*) /$1 break;
|
||||||
rewrite /something / break;
|
rewrite /something / break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
`, false},
|
`, false},
|
||||||
"redirect /something-complex to /not-root": {"/something-complex", "/not-root", "~* ^/something-complex", `
|
"redirect /end-with-slash/ to /not-root": {"/end-with-slash/", "/not-root", "~* ^/end-with-slash/(?<baseuri>.*)", `
|
||||||
|
rewrite /end-with-slash/(.*) /not-root/$1 break;
|
||||||
|
proxy_pass http://upstream-name;
|
||||||
|
`, false},
|
||||||
|
"redirect /something-complex to /not-root": {"/something-complex", "/not-root", `~* ^/something-complex\/?(?<baseuri>.*)`, `
|
||||||
rewrite /something-complex/(.*) /not-root/$1 break;
|
rewrite /something-complex/(.*) /not-root/$1 break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
`, false},
|
`, false},
|
||||||
"redirect / to /jenkins and rewrite": {"/", "/jenkins", "~* /", `
|
"redirect / to /jenkins and rewrite": {"/", "/jenkins", "~* /", `
|
||||||
rewrite /(.*) /jenkins/$1 break;
|
rewrite /(.*) /jenkins/$1 break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name/jenkins/">' r;
|
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$http_host/$baseuri">' r;
|
||||||
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name/jenkins/">' r;
|
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$http_host/$baseuri">' r;
|
||||||
`, true},
|
`, true},
|
||||||
"redirect /something to / and rewrite": {"/something", "/", "~* ^/something", `
|
"redirect /something to / and rewrite": {"/something", "/", `~* ^/something\/?(?<baseuri>.*)`, `
|
||||||
rewrite /something/(.*) /$1 break;
|
rewrite /something/(.*) /$1 break;
|
||||||
rewrite /something / break;
|
rewrite /something / break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name/">' r;
|
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$http_host/something/$baseuri">' r;
|
||||||
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name/">' r;
|
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$http_host/something/$baseuri">' r;
|
||||||
`, true},
|
`, true},
|
||||||
"redirect /something-complex to /not-root and rewrite": {"/something-complex", "/not-root", "~* ^/something-complex", `
|
"redirect /end-with-slash/ to /not-root and rewrite": {"/end-with-slash/", "/not-root", `~* ^/end-with-slash/(?<baseuri>.*)`, `
|
||||||
|
rewrite /end-with-slash/(.*) /not-root/$1 break;
|
||||||
|
proxy_pass http://upstream-name;
|
||||||
|
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$http_host/end-with-slash/$baseuri">' r;
|
||||||
|
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$http_host/end-with-slash/$baseuri">' r;
|
||||||
|
`, true},
|
||||||
|
"redirect /something-complex to /not-root and rewrite": {"/something-complex", "/not-root", `~* ^/something-complex\/?(?<baseuri>.*)`, `
|
||||||
rewrite /something-complex/(.*) /not-root/$1 break;
|
rewrite /something-complex/(.*) /not-root/$1 break;
|
||||||
proxy_pass http://upstream-name;
|
proxy_pass http://upstream-name;
|
||||||
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name/not-root/">' r;
|
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$http_host/something-complex/$baseuri">' r;
|
||||||
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name/not-root/">' r;
|
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$http_host/something-complex/$baseuri">' r;
|
||||||
`, true},
|
`, true},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue