NginX代理GolangWEB,获取真实客户端IP

NginX 代理 Golang WEB,获取真实客户端IP

Golang

NginX

配置 NginX :

location / {

proxy_pass :8080;

resolver_timeout 30s;

proxy_set_header Host $http_host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

然后使用 Header.Get("X-Real-Ip") 获得真实的IP:

func NewRequest(r *http.Request) *Request {

request.RemoteAddr = r.Header.Get(“X-Real-Ip”)

}

如果喜欢这篇文章,就点个赞吧,O(∩_∩)O谢谢!

原文: