You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: correct scheme/host on self-referential URLs behind an HTTPS reverse proxy (#10482) (#10504)
* fix(http): harden BaseURL proxy scheme/host detection
Split comma-separated X-Forwarded-Proto and honor the RFC 7239 Forwarded
header so generated links use https behind common reverse-proxy setups.
Refs #10482
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* feat(http): honor explicit external base URL in BaseURL
When _external_base_url is set in the request context it dictates the
origin (scheme+host+port); the proxy path prefix is still appended.
Refs #10482
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* feat(config): generalize LOCALAI_BASE_URL to ExternalBaseURL
LOCALAI_BASE_URL now sets a single instance-wide external base URL used
for OAuth callbacks and all self-referential links. A Pre middleware
stamps it into the request context for middleware.BaseURL.
Refs #10482
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* docs: document LOCALAI_BASE_URL and reverse-proxy headers
Refs #10482
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* test(http): cover parseForwarded edge cases; clarify base-url flag group
Adds direct unit coverage for quoted/malformed/multi-element Forwarded
headers and regroups the external base URL flag away from auth-only.
Refs #10482
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
AuthBaseURLstring`env:"LOCALAI_BASE_URL" help:"Base URL for OAuth callbacks (e.g. http://localhost:8080)" group:"auth"`
143
+
ExternalBaseURLstring`env:"LOCALAI_BASE_URL" help:"External base URL of this instance (e.g. https://localhost:8080). Used for OAuth callbacks and self-referential links (generated images/videos, job status). When unset, derived from X-Forwarded-Proto/Host or Forwarded headers." group:"api"`
144
144
AuthAdminEmailstring`env:"LOCALAI_ADMIN_EMAIL" help:"Email address to auto-promote to admin role" group:"auth"`
DisableLocalAuthbool`env:"LOCALAI_DISABLE_LOCAL_AUTH" default:"false" help:"Disable local email/password registration and login (use with OAuth/OIDC-only setups)" group:"auth"`
Copy file name to clipboardExpand all lines: docs/content/advanced/reverse-proxy-tls.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,26 @@ When running LocalAI behind a TLS termination reverse proxy, the Web UI may fail
14
14
15
15
LocalAI uses the `X-Forwarded-Proto` HTTP header to determine the protocol used by clients. When this header is set to `https`, LocalAI will generate HTTPS URLs for static assets in the Web UI.
16
16
17
+
## Running behind a reverse proxy (HTTPS / subpath)
18
+
19
+
LocalAI does not terminate TLS itself, so HTTPS is provided by a reverse
20
+
proxy in front of it. Self-referential links (generated image and video
21
+
URLs, async job status URLs, OAuth callbacks) need the externally visible
22
+
scheme, host and port.
23
+
24
+
LocalAI determines these in this order:
25
+
26
+
1.`LOCALAI_BASE_URL` - if set, it is authoritative for the origin. Set it to
27
+
the externally visible base URL, e.g. `LOCALAI_BASE_URL=https://localai.example.com`
28
+
or `https://192.168.0.13:34567`. Recommended whenever links come back with
29
+
the wrong scheme or host.
30
+
2. Otherwise, the `X-Forwarded-Proto` and `X-Forwarded-Host` headers (or the
31
+
RFC 7239 `Forwarded` header) sent by the proxy. Ensure your proxy forwards
32
+
`X-Forwarded-Proto: https`.
33
+
34
+
A reverse-proxy subpath mount is supported via `X-Forwarded-Prefix`; it is
35
+
appended to `LOCALAI_BASE_URL` when both are present.
36
+
17
37
## Required Headers
18
38
19
39
Your reverse proxy must forward these headers to LocalAI:
0 commit comments