diff options
-rw-r--r-- | docker-compose.yaml | 1 | ||||
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | icanhazallips.go | 15 | ||||
-rw-r--r-- | nginx.conf | 2 |
4 files changed, 19 insertions, 3 deletions
diff --git a/docker-compose.yaml b/docker-compose.yaml index 15b75f7..22f5dd0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3" services: icanhazallips: image: icanhazallips @@ -1,3 +1,5 @@ module icanhazallips -go 1.19 +go 1.24.0 + +require github.com/pires/go-proxyproto v0.8.0 diff --git a/icanhazallips.go b/icanhazallips.go index 1564ef4..48222bf 100644 --- a/icanhazallips.go +++ b/icanhazallips.go @@ -10,6 +10,8 @@ import ( "strconv" "strings" "time" + + "github.com/pires/go-proxyproto" ) const ( @@ -166,5 +168,16 @@ func main() { Handler: nil, } - log.Fatal(server.ListenAndServe()) + ln, err := net.Listen("tcp", config.Addr) + if err != nil { + log.Fatal(err) + } + + proxyListener := &proxyproto.Listener{ + Listener: ln, + ReadHeaderTimeout: time.Duration(config.ReadHeaderTimeout) * time.Second, + } + defer proxyListener.Close() + + log.Fatal(server.Serve(proxyListener)) } @@ -26,6 +26,8 @@ http { add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "no-referrer"; fastcgi_hide_header X-Powered-By; + proxy_set_header X-Real-IP $proxy_protocol_addr; + proxy_set_header X-Forwarded-For $proxy_protocol_addr; error_page 401 403 404 /404.html; location / { |