Configurable trusted proxy (FORWARDED_ALLOW_IPS); named deploy targets
FORWARDED_ALLOW_IPS (default 127.0.0.1) lets the app sit behind a proxy that reaches it over a Docker network instead of loopback; README shows the compose.override.yml for that. deploy.sh <name> picks HOST_<NAME> from the gitignored .deploy.env and leaves a server's compose.override.yml alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
21202c2ca3
commit
080fb451a6
4 changed files with 38 additions and 9 deletions
|
|
@ -8,5 +8,6 @@ COPY static ./static
|
|||
RUN useradd --system --uid 10001 tools && mkdir -p /data && chown tools /data
|
||||
USER tools
|
||||
ENV DATA_DIR=/data PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
# HOST/PORT come from compose; uvicorn trusts X-Forwarded-* only from loopback (the local proxy/tunnel).
|
||||
CMD ["sh", "-c", "exec uvicorn main:app --host ${HOST:-127.0.0.1} --port ${PORT:-8090} --proxy-headers --forwarded-allow-ips 127.0.0.1 --no-server-header"]
|
||||
# HOST/PORT come from compose. uvicorn trusts X-Forwarded-For only from FORWARDED_ALLOW_IPS
|
||||
# (IPs or CIDRs; default loopback), i.e. only from the reverse proxy in front of it.
|
||||
CMD ["sh", "-c", "exec uvicorn main:app --host ${HOST:-127.0.0.1} --port ${PORT:-8090} --proxy-headers --forwarded-allow-ips \"${FORWARDED_ALLOW_IPS:-127.0.0.1}\" --no-server-header"]
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ async def shutdown():
|
|||
|
||||
|
||||
def client_ip(request: Request) -> str:
|
||||
# uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind a
|
||||
# reverse proxy that connects over loopback this is already the visitor's address.
|
||||
# uvicorn runs with --proxy-headers and trusts X-Forwarded-For only from the proxy
|
||||
# (FORWARDED_ALLOW_IPS), so this is already the visitor's address.
|
||||
return request.client.host if request.client else ""
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue