Repository navigation
Reverse Proxy
Running Anchor LFS behind a reverse proxy is recommended for production deployments to provide TLS termination, additional security, and integration with your existing infrastructure.
Warning
Always set base_url in production. Without an explicit base_url, the server derives transfer URLs from X-Forwarded-Proto and X-Forwarded-Host request headers. Only peers in trusted_proxies can set those headers, but a misconfigured proxy, or a client on a trusted network, could still influence the generated URLs and redirect LFS transfers to a malicious server. Setting base_url explicitly eliminates this attack surface entirely.
For production use behind a reverse proxy, you have two options for ensuring correct URL generation:
Set base_url in your configuration to the external URL:
[options]
base_url = "https://lfs.example.com"This is the simplest and most reliable approach. The server uses this URL directly for all generated action hrefs, regardless of request headers.
If base_url is not set, the server derives URLs from request headers:
-
X-Forwarded-Proto: Must be set tohttps(orhttp) -
X-Forwarded-Host: Must be set to the external hostname (and port, if non-standard)
Your reverse proxy must set these headers, and its address must be in trusted_proxies (see below). The X-Forwarded-Host header is also validated by the server to prevent header injection attacks.
The server honours X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto only when the connection comes from an address in trusted_proxies, and removes them from every other request. By default this is loopback and the private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7), which covers a proxy on the same host, in the same Docker network, or on the LAN. A client connecting directly from a public address therefore cannot spoof the headers.
The client IP used for rate limiting and logging is the rightmost X-Forwarded-For address that is not itself in trusted_proxies, or the leftmost address when all of them are, so clients on your private network are told apart with the default ranges. Those clients count as trusted proxies too, though, so each can pick the address it is rate limited under by sending its own X-Forwarded-For. To prevent that, list only your proxy:
[options]
trusted_proxies = ["192.168.1.2"]If a CDN or other public proxy sits in front of your own proxy, add its published ranges as well. If nothing proxies the server, set trusted_proxies = [].
A trusted proxy can also send X-Request-ID, and the server then uses that ID in its response header and log lines instead of generating one, so a request can be followed through both logs. The ID must be 1 to 128 letters, digits, dots, underscores or hyphens; anything else is replaced. With Nginx, add proxy_set_header X-Request-ID $request_id; to the location block and include $request_id in the Nginx log format. Like the forwarded headers, X-Request-ID is removed from requests that do not come from a trusted proxy.
Anchor LFS sets no limit on how long a request may take, so a large upload or download runs for as long as data keeps flowing. It abandons an upload that sends no data for upload_idle_timeout (default 60 seconds) with 408. Configure your proxy the same way: no limit on the total length of a request, and idle timeouts no shorter than upload_idle_timeout.
| Proxy | Settings |
|---|---|
| Nginx |
proxy_read_timeout and proxy_send_timeout (the time between two reads or writes, 60 seconds by default), and client_max_body_size 0
|
| Caddy | None; it sets no read or write timeout by default |
| Apache |
TimeOut and ProxyTimeout (how long to wait for the next data, 60 seconds by default), and LimitRequestBody 0
|
| Traefik |
transport.respondingTimeouts.readTimeout on the entry point, which limits the whole request to 60 seconds by default; set it to 0
|
Keep your proxy's usual timeouts for other services.
upstream anchor_lfs {
server 127.0.0.1:5420;
keepalive 16;
}
server {
listen 443 ssl;
http2 on;
server_name lfs.example.com;
ssl_certificate /etc/ssl/certs/lfs.example.com.pem;
ssl_certificate_key /etc/ssl/private/lfs.example.com.key;
# Disable request body size limit (LFS files can be very large)
client_max_body_size 0;
# Increase timeouts for large file transfers
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_connect_timeout 10s;
# Disable request buffering (stream directly to backend)
proxy_request_buffering off;
location / {
proxy_pass http://anchor_lfs;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
# Pass through large responses without buffering
proxy_buffering off;
}
}
# Redirect HTTP to HTTPS
server {
listen 80;
server_name lfs.example.com;
return 301 https://$host$request_uri;
}The upstream block keeps connections to Anchor LFS open between requests (keepalive, with proxy_http_version 1.1 and an empty Connection header). HTTP/1.1 also lets Nginx stream uploads sent with chunked encoding instead of buffering them. http2 on; needs Nginx 1.25.1 or later; on older versions, use listen 443 ssl http2; instead.
services:
anchor-lfs:
image: ghcr.io/refringe/anchor-lfs:latest
volumes:
# On Linux hosts, create the data directory owned by the image's anchor user first:
# mkdir -p data && sudo chown 100:101 data
- ./data:/app/data
- ./config.toml:/app/config.toml:ro
restart: unless-stopped
stop_grace_period: 45s
nginx:
image: nginx:alpine
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
- /etc/ssl/certs:/etc/ssl/certs:ro
- /etc/ssl/private:/etc/ssl/private:ro
depends_on:
- anchor-lfs
restart: unless-stoppedIn the upstream block, point at the Docker service name:
server anchor-lfs:5420;lfs.example.com {
reverse_proxy localhost:5420
}
Caddy automatically handles TLS certificates via Let's Encrypt. No additional timeout configuration is needed as Caddy handles large transfers by default.
services:
anchor-lfs:
image: ghcr.io/refringe/anchor-lfs:latest
volumes:
# On Linux hosts, create the data directory owned by the image's anchor user first:
# mkdir -p data && sudo chown 100:101 data
- ./data:/app/data
- ./config.toml:/app/config.toml:ro
restart: unless-stopped
stop_grace_period: 45s
caddy:
image: caddy:alpine
ports:
- "443:443"
- "80:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- anchor-lfs
restart: unless-stopped
volumes:
caddy_data:
caddy_config:With this Caddyfile:
lfs.example.com {
reverse_proxy anchor-lfs:5420
}
Enable the required modules:
sudo a2enmod proxy proxy_http ssl headers<VirtualHost *:443>
ServerName lfs.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/lfs.example.com.pem
SSLCertificateKeyFile /etc/ssl/private/lfs.example.com.key
# Disable request body size limit
LimitRequestBody 0
# Increase timeouts for large transfers
ProxyTimeout 3600
TimeOut 3600
# Forward every request to Anchor LFS
ProxyPass / http://127.0.0.1:5420/ nocanon
ProxyPassReverse / http://127.0.0.1:5420/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Host "lfs.example.com"
</VirtualHost>
<VirtualHost *:80>
ServerName lfs.example.com
Redirect permanent / https://lfs.example.com/
</VirtualHost>services:
anchor-lfs:
image: ghcr.io/refringe/anchor-lfs:latest
volumes:
# On Linux hosts, create the data directory owned by the image's anchor user first:
# mkdir -p data && sudo chown 100:101 data
- ./data:/app/data
- ./config.toml:/app/config.toml:ro
labels:
- "traefik.enable=true"
- "traefik.http.routers.lfs.rule=Host(`lfs.example.com`)"
- "traefik.http.routers.lfs.entrypoints=websecure"
- "traefik.http.routers.lfs.tls.certresolver=letsencrypt"
- "traefik.http.services.lfs.loadbalancer.server.port=5420"
restart: unless-stopped
stop_grace_period: 45s
traefik:
image: traefik:v3
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.websecure.address=:443
- --entrypoints.websecure.transport.respondingtimeouts.readtimeout=0
- --certificatesresolvers.letsencrypt.acme.email=admin@example.com
- --certificatesresolvers.letsencrypt.acme.storage=/certs/acme.json
- --certificatesresolvers.letsencrypt.acme.tlschallenge=true
ports:
- "443:443"
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- traefik_certs:/certs
restart: unless-stopped
volumes:
traefik_certs:Replace lfs.example.com with your hostname and admin@example.com with the email address for your Let's Encrypt account. Traefik obtains the certificate itself and redirects HTTP to HTTPS.
The readtimeout=0 line matters: Traefik's default read timeout of 60 seconds covers the whole request, so without it any upload that takes longer than a minute fails. Anchor LFS still abandons an upload that stops sending data (upload_idle_timeout).
When running behind a reverse proxy:
-
Restrict direct access: Bind Anchor LFS to
127.0.0.1:5420(or use Docker networking) so it's only accessible through the proxy -
Trust forwarded headers: Set
trusted_proxiesto your proxy's address so no other peer can supplyX-Forwarded-*headers, and have the proxy overwrite any client-supplied ones -
Use
base_url: Settingbase_urlis more reliable than depending on forwarded headers and eliminates header-based attack surface entirely
- Configuration: Full configuration reference
- Docker: Docker deployment
- Security: Security considerations