aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2025-05-01 20:55:00 +0000
committerterminaldweller <devi@terminaldweller.com>2025-05-01 20:55:00 +0000
commit137e164d028a18a9f4f251e2250553a6a3524d6c (patch)
treeb64225aee59912587b5477532606d78565b88e7c
parentusing nginx as reverse proxy now (diff)
downloadicanhazallips-137e164d028a18a9f4f251e2250553a6a3524d6c.tar.gz
icanhazallips-137e164d028a18a9f4f251e2250553a6a3524d6c.zip
added the proxy protocol to the server
-rw-r--r--docker-compose.yaml1
-rw-r--r--go.mod4
-rw-r--r--icanhazallips.go15
-rw-r--r--nginx.conf2
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
diff --git a/go.mod b/go.mod
index 6f0768c..e8954e0 100644
--- a/go.mod
+++ b/go.mod
@@ -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))
}
diff --git a/nginx.conf b/nginx.conf
index 5a9c8a3..b917535 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -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 / {