mm-wiki icon indicating copy to clipboard operation
mm-wiki copied to clipboard

[Bug]通过Nginx反向代理后无法获取客户端真实IP

Open yearnxiao opened this issue 4 years ago • 3 comments

xxxxx这里是问题描述xxxx

  1. 当前使用的版本号 v0.2.1

  2. 是否已经升级到新版本 是

  3. 当前遇到的问题 通过Nginx反向代理后无法获取客户端真实IP

aa424

yearnxiao avatar Oct 16 '20 11:10 yearnxiao

目前通过修改以下两个函数做了修复,希望作者能根据自己的方式在下个版本中修复此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)

}`

yearnxiao avatar Oct 20 '20 06:10 yearnxiao

大佬,改了之后,重复登录的问题也没了

chaiyd avatar Jun 18 '21 02:06 chaiyd

大佬,改了之后,重复登录的问题也没了

对你有帮助就好

yearnxiao avatar Jul 02 '21 08:07 yearnxiao