diff options
author | terminaldweller <devi@terminaldweller.com> | 2025-05-01 20:59:37 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2025-05-01 20:59:37 +0000 |
commit | 1cac36f267f7c0953090c134b7afc0706ee080a8 (patch) | |
tree | ed0964289dc9ebbefda1343bc3ab3f240abc80f8 | |
parent | using nginx as reverse proxy now (diff) | |
download | icanhazallips-main2.tar.gz icanhazallips-main2.zip |
added the proxy protocol to the servermain2
-rw-r--r-- | docker-compose.yaml | 1 | ||||
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | main.go (renamed from icanhazallips.go) | 15 | ||||
-rw-r--r-- | nginx.conf | 2 |
5 files changed, 21 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 @@ -0,0 +1,2 @@ +github.com/pires/go-proxyproto v0.8.0 h1:5unRmEAPbHXHuLjDg01CxJWf91cw3lKHc/0xzKpXEe0= +github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY= diff --git a/icanhazallips.go b/main.go index 1564ef4..48222bf 100644 --- a/icanhazallips.go +++ b/main.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 / { |