Skip to content

Behind a reverse proxy ​

Run Harbor Pilot on the loopback address and put a reverse proxy in front of it to terminate TLS. The proxy has to cope with traffic that doesn't look like a website: coding tools stream replies for minutes at a time, send the whole conversation with every request, and sometimes wait a long time for a reply that is not streamed.

This page has a tested configuration for nginx, Apache httpd, Caddy, Traefik and HAProxy, and notes for Cloudflare Tunnel and Kubernetes. The files are in deploy/proxies.

What the proxy has to do ​

NeedWhyA default that breaks it
Pass streamed replies on as they are writtenTools show text as it arrives and give up on a stream that stays silent.None of the five proxies held a stream back, with or without compression; check any other proxy with the script below.
Accept request bodies up to 32 MiBEvery request carries the whole conversation, including pasted files and images.nginx refuses anything over 1 MB with 413 Request Entity Too Large.
Wait minutes for a reply that is not streamedSome tools and SDK calls ask for the whole reply at once, which arrives when the model finishes.nginx gives up after 60 seconds with 504 Gateway Timeout, Apache with 502 Bad Gateway.
Keep a quiet stream openWhile a model thinks, the only bytes on a stream are Harbor Pilot's keepalives, one every 15 seconds.A proxy timeout shorter than 15 seconds between bytes.
Forward the client's addressAudit entries, sign-in rate limits and request pages use it.Without trusted_proxies, every client looks like the proxy and they share one sign-in rate limit.

Harbor Pilot already helps: on a stream it sends response headers within 10 seconds even when the provider is slow, sends Cache-Control: no-cache and X-Accel-Buffering: no, and then a keepalive every 15 seconds. WebSockets are not used, so no Upgrade handling is needed.

Harbor Pilot settings ​

Whichever proxy you use, tell Harbor Pilot its public address and which proxy to believe:

yaml
server:
  listen: 127.0.0.1:8080
  public_url: https://pilot.example.com   # HP_PUBLIC_URL
  trusted_proxies: ["127.0.0.1/32"]       # the proxy's address
  • public_url must be the https:// address people and tools use. Session cookies are only marked Secure under HTTPS, changes from the web UI are only accepted from this origin, and setup links and tool snippets are built from it.
  • trusted_proxies lists the proxy's address, so the client address is taken from X-Forwarded-For: Harbor Pilot walks the header from the right and uses the first address that is not a trusted proxy. When Harbor Pilot runs in Docker and the proxy on the host, the proxy connects from the Docker network's gateway, not from 127.0.0.1: list that network instead (for example ["172.16.0.0/12"]).
  • With any trusted_proxies set, /metrics always needs server.metrics_token_file, because every request now arrives from the proxy. See Monitoring.

nginx ​

Needs nginx 1.25.1 or later for http2 on. Save as /etc/nginx/conf.d/harbor-pilot.conf:

nginx
# Harbor Pilot behind nginx (1.25.1 or later), terminating TLS.
#
# Save as /etc/nginx/conf.d/harbor-pilot.conf, replace pilot.example.com and the certificate paths, and set
# Harbor Pilot's server.public_url to https://pilot.example.com and server.trusted_proxies to ["127.0.0.1/32"].

server {
    listen 80;
    listen [::]:80;
    server_name pilot.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name pilot.example.com;

    ssl_certificate     /etc/letsencrypt/live/pilot.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/pilot.example.com/privkey.pem;

    # Tools send the whole conversation with every request. nginx refuses bodies over 1 MB by default;
    # Harbor Pilot accepts up to 32 MiB.
    client_max_body_size 32m;

    location / {
        proxy_pass http://127.0.0.1:8080;
        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;

        # Pass replies and requests through as they arrive instead of spooling them to disk first.
        proxy_buffering off;
        proxy_request_buffering off;

        # A reply that is not streamed arrives in one piece when the model finishes, which can take minutes.
        # The default of 60 seconds cuts it off with a 504.
        proxy_read_timeout 15m;
        proxy_send_timeout 15m;
    }
}

client_max_body_size and proxy_read_timeout are the two settings nginx's defaults get wrong. Streaming works without extra care: Harbor Pilot's X-Accel-Buffering: no already tells nginx not to buffer, and proxy_buffering off also stops nginx spooling large replies to disk.

Apache httpd ​

Enable the modules first: a2enmod proxy proxy_http ssl headers. Save as /etc/apache2/sites-available/harbor-pilot.conf and run a2ensite harbor-pilot:

apache
# Harbor Pilot behind Apache httpd 2.4, terminating TLS.
#
#   a2enmod proxy proxy_http ssl headers
#
# Save as /etc/apache2/sites-available/harbor-pilot.conf (then a2ensite harbor-pilot), replace pilot.example.com
# and the certificate paths, and set Harbor Pilot's server.public_url to https://pilot.example.com and
# server.trusted_proxies to ["127.0.0.1/32"].

<VirtualHost *:80>
    ServerName pilot.example.com
    Redirect permanent / https://pilot.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName pilot.example.com

    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/pilot.example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/pilot.example.com/privkey.pem

    # Harbor Pilot accepts requests up to 32 MiB.
    LimitRequestBody 33554432

    # A reply that is not streamed arrives in one piece when the model finishes, which can take minutes.
    ProxyTimeout 900

    # mod_proxy adds X-Forwarded-For. flushpackets=on sends each piece of a streamed reply on at once.
    ProxyPreserveHost On
    ProxyPass        / http://127.0.0.1:8080/ flushpackets=on
    ProxyPassReverse / http://127.0.0.1:8080/
    RequestHeader set X-Forwarded-Proto "https"
</VirtualHost>

ProxyTimeout is the setting Apache's default gets wrong: without it, a reply that is not streamed fails with 502 Bad Gateway after 60 seconds. Apache forwards X-Forwarded-For by itself.

Caddy ​

Caddy gets and renews the certificate itself, forwards Host and X-Forwarded-For, has no response timeout and passes text/event-stream on as it arrives:

txt
# Harbor Pilot behind Caddy 2, which gets and renews the certificate itself.
#
# Replace pilot.example.com, and set Harbor Pilot's server.public_url to https://pilot.example.com and
# server.trusted_proxies to ["127.0.0.1/32"].

pilot.example.com {
	# Harbor Pilot accepts requests up to 32 MiB.
	request_body {
		max_size 32MiB
	}

	# Caddy forwards Host and X-Forwarded-For and has no response timeout by default. flush_interval -1 passes
	# every write on straight away (Caddy does this for text/event-stream by itself; this makes it explicit).
	reverse_proxy 127.0.0.1:8080 {
		flush_interval -1
	}
}

Compression with encode is fine: Caddy still sends each event on as it arrives.

Traefik ​

Traefik v3 with the file provider. The static configuration, /etc/traefik/traefik.yml:

yaml
# Harbor Pilot behind Traefik v3: static configuration (/etc/traefik/traefik.yml).
# The route itself is in dynamic/harbor-pilot.yml. Set Harbor Pilot's server.public_url to
# https://pilot.example.com and server.trusted_proxies to Traefik's address.

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"

certificatesResolvers:
  letsencrypt:
    acme:
      email: admin@example.com
      storage: /etc/traefik/acme.json
      httpChallenge:
        entryPoint: web

providers:
  file:
    directory: /etc/traefik/dynamic

The route, /etc/traefik/dynamic/harbor-pilot.yml:

yaml
# Harbor Pilot behind Traefik v3: the route (/etc/traefik/dynamic/harbor-pilot.yml).
#
# Traefik passes streamed replies on as they are written, forwards Host and X-Forwarded-For, and has no response
# timeout by default, so no extra settings are needed.

http:
  routers:
    harbor-pilot:
      rule: Host(`pilot.example.com`)
      entryPoints: [websecure]
      service: harbor-pilot
      tls:
        certResolver: letsencrypt
  services:
    harbor-pilot:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:8080

Traefik's defaults suit Harbor Pilot: it streams, forwards X-Forwarded-For and has no response timeout. A compress middleware is fine too: Traefik still sends each event on as it arrives. With Docker labels instead of the file provider, the same router and service become traefik.http.routers.harbor-pilot.* and traefik.http.services.harbor-pilot.loadbalancer.server.port=8080 labels on the Harbor Pilot container.

HAProxy ​

HAProxy wants the certificate and key in one file: cat fullchain.pem privkey.pem > /etc/haproxy/certs/pilot.pem.

txt
# Harbor Pilot behind HAProxy 2.4 or later, terminating TLS.
#
# HAProxy wants the certificate and key in one file: cat fullchain.pem privkey.pem > /etc/haproxy/certs/pilot.pem.
# Set Harbor Pilot's server.public_url to https://pilot.example.com and server.trusted_proxies to ["127.0.0.1/32"].

global
    log stdout format raw local0

defaults
    mode http
    log global
    option httplog
    timeout connect 5s
    timeout http-request 30s
    # A reply that is not streamed arrives in one piece when the model finishes, which can take minutes.
    # Streams are safe either way: Harbor Pilot sends a keepalive every 15 seconds.
    timeout client 15m
    timeout server 15m

frontend https
    bind :80
    bind :443 ssl crt /etc/haproxy/certs/pilot.pem alpn h2,http/1.1
    http-request redirect scheme https unless { ssl_fc }
    option forwardfor
    http-request set-header X-Forwarded-Proto https
    default_backend harbor_pilot

# HAProxy streams replies as they come and has no body size limit, so nothing else is needed.
backend harbor_pilot
    option httpchk GET /healthz
    server pilot 127.0.0.1:8080 check

HAProxy streams and has no body size limit; timeout client and timeout server are the settings that matter. The health check uses /healthz, so HAProxy stops sending traffic while Harbor Pilot restarts.

Cloudflare Tunnel ​

cloudflared connects out to Cloudflare, so nothing needs to listen publicly: point the tunnel's ingress at http://127.0.0.1:8080 and set public_url to the tunnel's hostname. Two Cloudflare limits apply (from Cloudflare's documentation; the check script below does not run against Cloudflare):

  • A request that gets no response for 100 seconds fails with error 524. Streamed requests are not affected, because Harbor Pilot sends headers within 10 seconds and keepalives every 15, but a long reply that is not streamed is. Coding tools stream by default.
  • Request bodies are limited by your Cloudflare plan (100 MB on the Free and Pro plans), above Harbor Pilot's 32 MiB.

cloudflared itself connects to Harbor Pilot from 127.0.0.1, so trusted_proxies: ["127.0.0.1/32"] applies.

Other proxies and Kubernetes ​

Any proxy works if it meets the five needs above. On Kubernetes, the same settings apply to whichever ingress controller or gateway you run, with trusted_proxies set to its pods' network.

How these were checked ​

scripts/proxy-check.sh runs each proxy in Docker with the file from deploy/proxies (with the hostname, ports and certificate paths swapped for local ones) and checks it twice:

  1. In front of a stand-in backend that answers like the gateway: five events one second apart must arrive one by one (with Accept-Encoding: gzip, deflate, br, zstd set, as tools send it); a 75-second stream that carries nothing but keepalives must stay open; a reply that takes two minutes and is not streamed must arrive; a 20 MiB request must be accepted; and X-Forwarded-For must reach the backend.
  2. In front of the real demo: the web UI loads, and signing in and out works, which needs the Secure session cookie and the origin check against public_url.
sh
scripts/proxy-check.sh                # every proxy, about 12 minutes
scripts/proxy-check.sh nginx caddy    # only these
QUICK=1 scripts/proxy-check.sh        # skip the 75-second and 2-minute checks

To be sure the checks catch problems, they were also run against broken configurations: nginx without client_max_body_size fails with 413, and without proxy_read_timeout with 504; Apache without ProxyTimeout fails with 502. Compression turned on for streams (nginx gzip_types text/event-stream, Apache mod_deflate, Caddy encode, Traefik compress) did not hold events back in any of them.

Last run: 2026-11-06, Harbor Pilot at main, every check passing:

ProxyVersion
nginx1.29.8
Apache httpd2.4.69
Caddy2.11.9
Traefik3.7.17
HAProxy3.2.26

Released under the Apache-2.0 License.