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 +}