Home / golang

Golang Gin & Nginx to Get Real Ip of Visitors

Posted on:2020-04-23 Views:10750 Words:55

In the golang gin controller


Gets the IP of the request, but gets

Presumably Nginx was not configured when it forwarded the request to golang process.


Just add two lines to the configuration.

location /go/ {
        proxy_set_header X-Forward-For $remote_addr;
        proxy_set_header X-real-ip $remote_addr;

reload nginx, test, OK.