TLS Reverse Proxy Configuration
TLS Reverse Proxy Configuration
When running LocalAI behind a TLS termination reverse proxy, the Web UI may fail to load static assets (CSS, JS) correctly because the application doesn’t automatically detect that it’s being served over HTTPS. This guide explains how to properly configure your reverse proxy to work with LocalAI.
How It Works
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.
Required Headers
Your reverse proxy must forward these headers to LocalAI:
| Header | Purpose |
|---|---|
X-Forwarded-Proto | Set to https when TLS is terminated at the proxy |
X-Forwarded-Host | The original host requested by the client |
X-Forwarded-Prefix | Any path prefix if LocalAI is served under a sub-path |
HAProxy Configuration
Apache Configuration
Nginx Configuration
Serving Under a Sub-Path
If you serve LocalAI under a sub-path (e.g., https://your-domain.com/localai), you need to:
- Configure your reverse proxy to set the
X-Forwarded-Prefixheader
Example with Nginx:
Testing Your Configuration
- Start LocalAI:
localai - Configure your reverse proxy as shown above
- Access the Web UI through the proxy
- Check the browser’s developer console for any mixed content warnings or failed asset loads
- Verify that the HTML source contains
https://URLs for static assets
Troubleshooting
Static Assets Not Loading
- Verify the
X-Forwarded-Protoheader is being forwarded - Check that the header value is exactly
https(lowercase) - Inspect the network tab in your browser to see which requests are failing
Mixed Content Warnings
- Ensure LocalAI is generating HTTPS URLs (check the BaseURL middleware is working)
- Verify the
X-Forwarded-Protoheader is set before LocalAI processes the request
Redirect Loops
- Check that your proxy is not adding duplicate headers
- Verify
X-Forwarded-Protois not being set to bothhttpandhttps
Security Note
When using reverse proxies, ensure your proxy only accepts connections from trusted sources and properly validates SSL certificates. Never expose LocalAI directly to the internet without TLS termination.