From 3aa62f91bfe992e00bc53627fe3e52647f012eb4 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 29 May 2024 15:49:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=20PHP=20=E7=8E=AF=E5=A2=83=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=BD=91=E7=AB=99=E4=B9=8B=E5=90=8E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=20(#5198?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/5163 --- backend/app/service/website_utils.go | 10 +++++----- backend/utils/files/utils.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index d63b052d5..5c9ebab0d 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -726,15 +726,15 @@ func opWebsite(website *model.Website, operate string) error { 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) { + fileOp := files.NewFileOp() + if fileOp.Stat(absoluteIncludeDir) && !files.IsEmptyDir(absoluteIncludeDir) { + proxyInclude := fmt.Sprintf("/www/sites/%s/proxy/*.conf", website.Alias) 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) { + if fileOp.Stat(absoluteRewritePath) { server.UpdateDirective("include", []string{rewriteInclude}) } rootIndex := path.Join("/www/sites", website.Alias, "index") @@ -763,7 +763,7 @@ func opWebsite(website *model.Website, operate string) error { return err } if runtime.Type == constant.RuntimePHP { - if website.ProxyType == constant.RuntimeProxyUnix { + if website.ProxyType == constant.RuntimeProxyUnix || website.ProxyType == constant.RuntimeProxyTcp { localPath = path.Join(nginxInstall.Install.GetPath(), rootIndex, "index.php") } server.UpdatePHPProxy([]string{website.Proxy}, localPath) diff --git a/backend/utils/files/utils.go b/backend/utils/files/utils.go index c8cc6218c..206910d0a 100644 --- a/backend/utils/files/utils.go +++ b/backend/utils/files/utils.go @@ -128,3 +128,13 @@ func GetParentMode(path string) (os.FileMode, error) { func IsInvalidChar(name string) bool { return strings.Contains(name, "&") } + +func IsEmptyDir(dir string) bool { + f, err := os.Open(dir) + if err != nil { + return false + } + defer f.Close() + _, err = f.Readdirnames(1) + return err == io.EOF +}