mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-05-08 12:52:44 -05:00
[PR #237] [MERGED] fix: improve reverse proxy support for subdomain deployments #1100
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/237
Author: @arunavo4
Created: 3/18/2026
Status: ✅ Merged
Merged: 3/18/2026
Merged by: @arunavo4
Base:
main← Head:fix/63-reverse-proxy-support📝 Commits (4)
470be29fix: improve reverse proxy support for subdomain deployments (#63)9b99e5efix: address review findings for reverse proxy origin detection60034c5fix: handle multi-value x-forwarded-host in chained proxy setups2e2b420test: add unit tests for reverse proxy origin detection📊 Changes
7 files changed (+268 additions, -46 deletions)
View changed files
📝
.env.example(+18 -1)📝
docker-compose.alt.yml(+4 -0)📝
docker-compose.yml(+7 -0)➕
src/lib/auth-origins.test.ts(+119 -0)📝
src/lib/auth.ts(+71 -42)📝
src/pages/api/sse/index.ts(+1 -0)📝
src/pages/docs/advanced.astro(+48 -3)📄 Description
Summary
Fixes #63 — app doesn't work when accessed via a reverse proxy subdomain (e.g.,
gitea-mirror.mydomain.tld). Pages show no content and users can't sign in.Root cause
Better Auth's
trustedOriginsonly includedhttp://localhost:4321by default. When the browser sendsOrigin: https://gitea-mirror.mydomain.tld, it was rejected as "invalid origin". Additionally, SSE streams were buffered by Nginx, breaking real-time updates.Changes
Auto-detect origin from request headers (
src/lib/auth.ts)trustedOriginsfrom a static IIFE to an async function that receives the incoming requestX-Forwarded-Host/Host+X-Forwarded-Protoheaders for per-request CSRF validationX-Forwarded-HostandX-Forwarded-Proto(chained proxy setups) — takes first value only"http"or"https"SSE buffering fix (
src/pages/api/sse/index.ts)X-Accel-Buffering: noresponse header to prevent Nginx from buffering the SSE streamDocumentation (
src/pages/docs/advanced.astro)BETTER_AUTH_URL,PUBLIC_BETTER_AUTH_URL, andBETTER_AUTH_TRUSTED_ORIGINSare mandatory for reverse proxy deploymentsX-Forwarded-For,X-Forwarded-Proto,Hostheaders to Nginx SSE exampleConfig/Docker (
.env.example,docker-compose.yml,docker-compose.alt.yml).env.examplePUBLIC_BETTER_AUTH_URLandBETTER_AUTH_TRUSTED_ORIGINStodocker-compose.ymldocker-compose.alt.ymlTest plan
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.