All systems operational
Cloudphere
← Documentation

Real visitor IP addresses

Every request reaches your app through Cloudphere's proxy, which handles HTTPS and routing. Unless your app is told to trust that proxy, it sees the proxy's address on every request instead of the visitor's.

Why it matters

What Cloudphere sends

Two headers on every request:

X-Forwarded-For
The visitor's IP address is the last entry. Anything before it came from the visitor's own request and can't be trusted.
X-Forwarded-Proto
https for every public request.

Your app is only reachable through the proxy, never directly from the internet, so trusting it is safe.

Turn it on

One change, then deploy.

Laravel 11 and later

bootstrap/app.php

->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})

On Laravel 10, set protected $proxies = '*'; in app/Http/Middleware/TrustProxies.php instead.

Express

app.js

const app = express();
app.set("trust proxy", 1); // trust the one proxy in front of the app

Django

settings.py

SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# The visitor is the last address in X-Forwarded-For:
def client_ip(request):
    forwarded = request.META.get("HTTP_X_FORWARDED_FOR", "")
    return forwarded.split(",")[-1].strip() or request.META.get("REMOTE_ADDR")

Ruby on Rails

No change needed

# Rails already trusts private network proxies, which is what
# Cloudphere's proxy is. request.remote_ip returns the visitor's address.

Next.js (route handlers and middleware)

app/api/example/route.ts

export function GET(request: Request) {
  const forwarded = request.headers.get("x-forwarded-for") ?? "";
  const ip = forwarded.split(",").pop()?.trim();
  // ...
}

Check it works

Open Shell for your service in the console and log the address your app sees for a request from your browser. It should match the address shown by any “what is my IP” site, not an internal 172. address.