Skip to content

Client IP addresses

Requests reach your app through the DockHive edge, so the network peer your app sees is the platform, not the visitor. The visitor’s real address is passed in two headers:

  • X-Real-IP: the visitor’s IP address.
  • X-Forwarded-For: a comma-separated list. The leftmost entry is the visitor; entries after it are DockHive’s own hops and can be ignored.

Static sites (HTML, React, Vue, Svelte, Angular and Vite builds) need no changes: the built-in web server records the visitor’s address in your runtime logs. Redeploy an older site once to pick this up.

const app = express();
app.set('trust proxy', true); // read the visitor from X-Forwarded-For
app.get('/', (req, res) => {
res.send(`Hello ${req.ip}`); // the visitor's address
});

Without a framework, use req.headers['x-real-ip'], or the first item of req.headers['x-forwarded-for'].split(',').

from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1)
# request.remote_addr is now the visitor's address

Django doesn’t rewrite REMOTE_ADDR on its own. Read the header directly:

def client_ip(request):
real_ip = request.META.get("HTTP_X_REAL_IP")
if real_ip:
return real_ip
forwarded = request.META.get("HTTP_X_FORWARDED_FOR", "")
return forwarded.split(",")[0].strip() or request.META.get("REMOTE_ADDR")

Also set SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") so Django knows requests arrived over HTTPS.

Read request.headers.get("x-real-ip"), or start Uvicorn with --proxy-headers --forwarded-allow-ips="*" so request.client.host is the visitor.