使用 bee api myapi 生成 myapi 项目用于处理 API 接口
由于前端使用了 nginx 做反向代理,所以通过 beego 框架内 提供的方法
Input.IP()获取到的IP是内网IP。不满足需求
nginx 代理中已经设置
location / {
proxy_set_header X-real-ip $remote_addr;
proxy_pass http://upstream/;
}
beego 中可以通过如下代码获取到真实IP
func (u *IpController) Get() {
//u.Data["json"] = u.Ctx.Input.IP()
u.Data["json"] = u.Ctx.Request.Header.Get("X-Real-ip")//nginx 中proxy_set_header 设置的值
u.ServeJSON()
}









网友评论