From e672d1d896bdaf1e01cf23c7e6356969c3598423 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 5 May 2023 14:02:54 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8F=8D=E5=90=91?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=BD=91=E7=AB=99=E5=81=9C=E6=AD=A2=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20(#878)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/website_utils.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index 16b9ee03b..c0aa74859 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -497,16 +497,32 @@ func opWebsite(website *model.Website, operate string) error { } server := servers[0] if operate == constant.StopWeb { - if website.Type == constant.Deployment || website.Type == constant.Static || website.Type == constant.Proxy { + proxyInclude := fmt.Sprintf("/www/sites/%s/proxy/*.conf", website.Alias) + server.RemoveDirective("include", []string{proxyInclude}) + rewriteInclude := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.Alias, website.Alias) + server.RemoveDirective("include", []string{rewriteInclude}) + + switch website.Type { + case constant.Deployment: server.RemoveDirective("location", []string{"", "/"}) - } - if website.Type == constant.Runtime { + case constant.Runtime: server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"}) } server.UpdateRoot("/usr/share/nginx/html/stop") website.Status = constant.WebStopped } if operate == constant.StartWeb { + proxyInclude := fmt.Sprintf("/www/sites/%s/proxy/*.conf", website.Alias) + absoluteIncludeDir := path.Join(nginxInstall.Install.GetPath(), fmt.Sprintf("/www/sites/%s/proxy", website.Alias)) + if files.NewFileOp().Stat(absoluteIncludeDir) { + server.UpdateDirective("include", []string{proxyInclude}) + } + server.UpdateDirective("include", []string{proxyInclude}) + rewriteInclude := fmt.Sprintf("/www/sites/%s/rewrite/%s.conf", website.Alias, website.Alias) + absoluteRewritePath := path.Join(nginxInstall.Install.GetPath(), rewriteInclude) + if files.NewFileOp().Stat(absoluteRewritePath) { + server.UpdateDirective("include", []string{rewriteInclude}) + } switch website.Type { case constant.Deployment: server.RemoveDirective("root", nil) @@ -521,7 +537,6 @@ func opWebsite(website *model.Website, operate string) error { server.UpdateRootLocation() case constant.Proxy: server.RemoveDirective("root", nil) - server.UpdateRootProxy([]string{website.Proxy}) case constant.Runtime: rootIndex := path.Join("/www/sites", website.Alias, "index") server.UpdateRoot(rootIndex)