mm-wiki
mm-wiki copied to clipboard
[Bug]通过Nginx反向代理后无法获取客户端真实IP
xxxxx这里是问题描述xxxx
-
当前使用的版本号 v0.2.1
-
是否已经升级到新版本 是
-
当前遇到的问题 通过Nginx反向代理后无法获取客户端真实IP
目前通过修改以下两个函数做了修复,希望作者能根据自己的方式在下个版本中修复此Bug. mm-wiki/app/controllers/template.go `func (this *TemplateController) GetClientIp() string { c_ip := this.Ctx.Input.IP() if c_ip == ""{ c_ip = strings.Split(this.Ctx.Request.RemoteAddr, ":")[0] } return c_ip
//s := strings.Split(this.Ctx.Request.RemoteAddr, ":")
//return s[0]
}`
mm-wiki/app/models/log.go `func (l *Log) RecordLog(message string, level int, userId string, username string, ctx context.Context) (id int64, err error) { userAgent := ctx.Request.UserAgent() referer := ctx.Request.Referer() getParams := ctx.Request.URL.String() path := ctx.Request.URL.Path ctx.Request.ParseForm() postParamsMap := map[string][]string(ctx.Request.PostForm) postParams, _ := json.Marshal(postParamsMap) c_ip := ctx.Input.IP() if c_ip == ""{ c_ip = strings.Split(ctx.Request.RemoteAddr, ":")[0] }
logValue := map[string]interface{}{
"level": level,
"path": path,
"get": getParams,
"post": string(postParams),
"message": message,
"ip": c_ip,
"user_agent": userAgent,
"referer": referer,
"user_id": userId,
"username": username,
"create_time": time.Now().Unix(),
}
return LogModel.Insert(logValue)
}`
大佬,改了之后,重复登录的问题也没了
大佬,改了之后,重复登录的问题也没了
对你有帮助就好