Determine the real IP address of the client for logging

When running behind a reverse proxy such as nginx, the remote IP as
logged is always that of the proxy. Figuring out the correct address
in this context is a little tricky, hence the following module is
used:

https://github.com/tomasen/realip
This commit is contained in:
A Kirkpatrick 2019-11-17 14:14:15 +10:30
parent d79d864825
commit 5fb7207d65
3 changed files with 7 additions and 1 deletions

View file

@ -5,6 +5,8 @@ import (
"net/http"
"strconv"
"github.com/tomasen/realip"
"github.com/filebrowser/filebrowser/v2/runner"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage"
@ -60,7 +62,8 @@ func handle(fn handleFunc, prefix string, storage *storage.Storage, server *sett
}
if status >= 400 || err != nil {
log.Printf("%s: %v %s %v", r.URL.Path, status, r.RemoteAddr, err)
clientIP := realip.FromRequest(r)
log.Printf("%s: %v %s %v", r.URL.Path, status, clientIP, err)
}
})