feat(nginx): performance optimization #850

This commit is contained in:
Jacky 2025-04-11 12:27:18 +00:00
parent b59da3e7e8
commit 9d4070a211
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
29 changed files with 4250 additions and 2031 deletions

36
api/nginx/performance.go Normal file
View file

@ -0,0 +1,36 @@
package nginx
import (
"net/http"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"github.com/uozi-tech/cosy"
)
// GetPerformanceSettings retrieves current Nginx performance settings
func GetPerformanceSettings(c *gin.Context) {
// Get Nginx worker configuration info
perfInfo, err := nginx.GetNginxWorkerConfigInfo()
if err != nil {
cosy.ErrHandler(c, err)
return
}
c.JSON(http.StatusOK, perfInfo)
}
// UpdatePerformanceSettings updates Nginx performance settings
func UpdatePerformanceSettings(c *gin.Context) {
var perfOpt nginx.PerfOpt
if !cosy.BindAndValid(c, &perfOpt) {
return
}
err := nginx.UpdatePerfOpt(&perfOpt)
if err != nil {
cosy.ErrHandler(c, err)
return
}
GetPerformanceSettings(c)
}

View file

@ -23,4 +23,8 @@ func InitRouter(r *gin.RouterGroup) {
r.POST("nginx/stub_status", ToggleStubStatus)
r.POST("nginx_log", nginx_log.GetNginxLogPage)
r.GET("nginx/directives", GetDirectives)
// Performance optimization endpoints
r.GET("nginx/performance", GetPerformanceSettings)
r.POST("nginx/performance", UpdatePerformanceSettings)
}