@@ -3,7 +3,6 @@ package nginx
33import (
44 "encoding/json"
55 "github.com/0xJacky/Nginx-UI/api"
6- "github.com/0xJacky/Nginx-UI/internal/helper"
76 "github.com/0xJacky/Nginx-UI/internal/logger"
87 "github.com/0xJacky/Nginx-UI/internal/nginx"
98 "github.com/gin-gonic/gin"
@@ -50,15 +49,21 @@ func GetNginxLogPage(c *gin.Context) {
5049 return
5150 }
5251
53- f , err := os .Open (logPath )
52+ logFileStat , err := os .Stat (logPath )
5453
5554 if err != nil {
5655 c .JSON (http .StatusOK , nginxLogPageResp {})
5756 logger .Error (err )
5857 return
5958 }
6059
61- logFileStat , err := os .Stat (logPath )
60+ if ! logFileStat .Mode ().IsRegular () {
61+ c .JSON (http .StatusOK , nginxLogPageResp {})
62+ logger .Error ("log file is not regular file:" , logPath )
63+ return
64+ }
65+
66+ f , err := os .Open (logPath )
6267
6368 if err != nil {
6469 c .JSON (http .StatusOK , nginxLogPageResp {})
@@ -188,8 +193,16 @@ func tailNginxLog(ws *websocket.Conn, controlChan chan controlStruct, errChan ch
188193 Whence : io .SeekEnd ,
189194 }
190195
191- if ! helper .FileExists (logPath ) {
192- errChan <- errors .New ("error log path not exists " + logPath )
196+ stat , err := os .Stat (logPath )
197+ if os .IsNotExist (err ) {
198+ errChan <- errors .New ("[error] log path not exists " + logPath )
199+ return
200+ }
201+
202+ if ! stat .Mode ().IsRegular () {
203+ errChan <- errors .New ("[error] " + logPath + " is not a regular file. " +
204+ "If you are using nginx-ui in docker container, please refer to " +
205+ "https://nginxui.com/zh_CN/guide/config-nginx-log.html for more information." )
193206 return
194207 }
195208
0 commit comments