gin icon indicating copy to clipboard operation
gin copied to clipboard

[Ask for help] sometimes access timeout when use nginx proxy

Open ycyxuehan opened this issue 1 year ago • 0 comments

i use nginx to proxy my gin service in same server, sometimes it can not access with a time out error from nginx, nginx log like this: 2022/05/30 09:44:01 [info] 83815#83815: *2609858 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 47.102.*.*, server: test.example.com, request: "GET /api/example/history HTTP/1.1", upstream: "http://192.168.0.23:8000/api/example/history", host: "test.example.com", referrer: "test.example.com" but i can access it by curl http://192.168.0.23:8000/api/example/history in the server, and it can fixed by restart gin service maybe it is not a issue of gin but this problem is very important and urgent for me, so I want to ask for help this is my code: ` func Init() *gin.Engine { // debug, release, test mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) r := gin.Default() // 是否打印访问日志, 在非正式环境都打印 if mode != "release" { r.Use(gin.Logger()) } r.GET("/favicon.ico", func(c *gin.Context) { c.Status(204) }) //prometheus interfaces now := time.Now() startedAt = &now r.Any("/metrics", func(c *gin.Context) { promhttp.Handler().ServeHTTP(c.Writer, c.Request) }) r.GET("/readiness", readiness) route(r.Group("/api")) return r }

func Run(file string) { r := Init() r.Run(cfg.PortAPI) logx.Info("Server exiting") }

func route(r *gin.RouterGroup) {...} ` thanks

ycyxuehan avatar May 30 '22 02:05 ycyxuehan