Skip to content

Commit

Permalink
feat: 网站 access_log 使用主配置文件参数 (#5255)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 committed Jun 3, 2024
1 parent 6011f35 commit caee215
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion backend/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,14 +1044,16 @@ func (w WebsiteService) OpWebsiteLog(req request.WebsiteLogReq) (*response.Websi
case constant.EnableLog:
key := "access_log"
logPath := path.Join("/www", "sites", website.Alias, "log", req.LogType)
params := []string{logPath}
switch req.LogType {
case constant.AccessLog:
params = append(params, "main")
website.AccessLog = true
case constant.ErrorLog:
key = "error_log"
website.ErrorLog = true
}
if err := updateNginxConfig(constant.NginxScopeServer, []dto.NginxParam{{Name: key, Params: []string{logPath}}}, &website); err != nil {
if err := updateNginxConfig(constant.NginxScopeServer, []dto.NginxParam{{Name: key, Params: params}}, &website); err != nil {
return nil, err
}
if err := websiteRepo.Save(context.Background(), &website); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/website_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
server.UpdateServerName(serverNames)

siteFolder := path.Join("/www", "sites", website.Alias)
server.UpdateDirective("access_log", []string{path.Join(siteFolder, "log", "access.log")})
server.UpdateDirective("access_log", []string{path.Join(siteFolder, "log", "access.log"), "main"})
server.UpdateDirective("error_log", []string{path.Join(siteFolder, "log", "error.log")})

rootIndex := path.Join("/www/sites", website.Alias, "index")
Expand Down

0 comments on commit caee215

Please sign in to comment.