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:
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user