title: Behind a Proxy
description: Configure JustAPI to run behind a reverse proxy (Nginx, Traefik, HAProxy, Cloudflare).
keywords: [JustAPI, reverse proxy, Nginx, Traefik, root_path, X-Forwarded]
root_path
When running behind a proxy, set root_path so JustAPI knows the external path:
app = JustAPIApp(root_path="/api/v1")
Nginx Configuration
location /api/ {
proxy_pass http://localhost:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Cloudflare
Cloudflare automatically adds the right headers. JustAPI detects them:
app = JustAPIApp(root_path="/")
Trusted Hosts with Proxy
from starlette.middleware.trustedhost import TrustedHostMiddleware
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=["example.com", "*.example.com"],
)
See Also
- Docker — containerized deployment
- Kubernetes / Helm — K8s deployment
- Production Checklist — production setup