GenHTTP Lambda Docs

Running a server

Addresses, HTTPS and domains

Give the installation its public address, put HTTPS in front of it with Caddy, nginx or Traefik or the server itself, serve apps at subdomains, and give production apps domains of their own.

The server speaks plain HTTP on port 8080. For an installation others use, give it a public address, terminate HTTPS in front of it or in it, and decide where the apps answer.

The public address#

Set LAMBDA_PUBLIC_URL to the address people and agents use, such as https://lambda.example.com - a host name or an IPv4 address, without a path. The apps’ addresses below /lambda/, the MCP address on /ship, the guide agents read and the sitemap are made from it. The links an agent is handed - an app’s editor link, its git address, a draft’s preview - are made from the address the agent called, as the proxy forwards it.

Once it is set, the server answers only at that host, at localhost and at the hosts in LAMBDA_MCP_ORIGINS - and at the hosts of apps. Any other name pointed at the server gets a page saying nothing is online there. Leave it unset while you reach the server by its IP address; the addresses it hands out then read http://localhost:8080.

HTTPS with a reverse proxy#

The usual setup: the reverse proxy you already run terminates TLS and forwards everything for the host to port 8080, with one entry for the whole installation.

Caddy

Caddyfile

lambda.example.com {
    reverse_proxy localhost:8080
}

Caddy fetches the certificate itself, keeps the Host header, sets X-Forwarded-For and X-Forwarded-Proto, and passes websockets and server-sent events through as they are.

nginx

nginx.conf (inside http { … })

map $http_upgrade $connection_upgrade { default upgrade; '' close; }

server {
    listen 443 ssl;
    server_name lambda.example.com;
    ssl_certificate     /etc/letsencrypt/live/lambda.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/lambda.example.com/privkey.pem;

    client_max_body_size 256m;                  # git pushes and uploads

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;            # required: the platform routes by host
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;   # links handed to agents read https
        proxy_set_header Upgrade $http_upgrade; # websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_buffering off;                    # server-sent events
        proxy_read_timeout 1h;                  # long-lived connections
    }
}

Traefik

docker-compose.yml (labels of the lambda service)

    labels:
      - traefik.enable=true
      - traefik.http.routers.lambda.rule=Host(`lambda.example.com`)
      - traefik.http.routers.lambda.entrypoints=websecure
      - traefik.http.routers.lambda.tls.certresolver=letsencrypt
      - traefik.http.services.lambda.loadbalancer.server.port=8080

Traefik keeps the Host header and sets X-Forwarded-For and X-Forwarded-Proto by default. Leave out the ports of the service: Traefik reaches it on the Docker network.

TLS in the server#

Without a proxy, the server terminates TLS itself. There is no ACME client built in; certbot works well with the server answering its challenges from LAMBDA_ACME_DIRECTORY. The server loads its certificate as it starts and refuses to start without it, so the first one is issued while it runs on plain HTTP:

  1. Start it on port 80 with the challenge folder, without TLS:

    Shell

    docker run -d --name lambda -p 80:80 \
      -v lambda-data:/data -v /opt/genhttp-lambda/acme:/acme:ro \
      -e LAMBDA_PUBLIC_URL=https://lambda.example.com -e LAMBDA_PORT=80 \
      -e LAMBDA_ACME_DIRECTORY=/acme \
      genhttp/lambda
    
  2. Issue the certificate, and make it readable for the container’s user (lambda, uid 1001):

    Shell

    certbot certonly --webroot -w /opt/genhttp-lambda/acme -d lambda.example.com
    
    mkdir -p /opt/genhttp-lambda/certs
    install -m 0644 -o root -g 1001 /etc/letsencrypt/live/lambda.example.com/fullchain.pem /opt/genhttp-lambda/certs/
    install -m 0640 -o root -g 1001 /etc/letsencrypt/live/lambda.example.com/privkey.pem   /opt/genhttp-lambda/certs/
    
  3. Start it again with TLS:

    Shell

    docker rm -f lambda
    docker run -d --name lambda -p 80:80 -p 443:443 \
      -v lambda-data:/data -v /opt/genhttp-lambda/certs:/certs:ro -v /opt/genhttp-lambda/acme:/acme:ro \
      -e LAMBDA_PUBLIC_URL=https://lambda.example.com \
      -e LAMBDA_PORT=80 -e LAMBDA_TLS_PORT=443 \
      -e LAMBDA_CERTIFICATE=/certs/fullchain.pem -e LAMBDA_CERTIFICATE_KEY=/certs/privkey.pem \
      -e LAMBDA_CERTIFICATE_DIRECTORY=/certs -e LAMBDA_ACME_DIRECTORY=/acme \
      genhttp/lambda
    

Publish the ports under the numbers the server listens on: it redirects plain requests to its TLS port by number, so a mapping that renumbers them sends visitors to a port that is not open. (Ports below 1024 inside the container need Docker 20.10 or later.) The challenges keep being answered over plain HTTP.

Run the install lines from a certbot deploy hook for renewals. The internal and kestrel engines pick up a renewed file without a restart; a certificate for a new host name in LAMBDA_CERTIFICATE_DIRECTORY is found on the next start.

Apps at subdomains#

By default, apps answer below /lambda/ on the installation’s address. That takes nothing but the one name - and every app shares the platform’s origin in the browser, so a page of one app can read what the editor and the panel keep there, and what other apps keep. Fine for apps you and your team build; for apps of people you do not know, give every app a host of its own:

Shell

-e LAMBDA_HOSTING_URL=https://apps.example.com
  1. DNS: point *.apps.example.com and apps.example.com at the server.
  2. Certificate: one for both names. A wildcard is issued only with a DNS challenge - certbot’s plugin for your DNS provider, or your proxy’s DNS integration. With TLS in the server, put it in its own folder of LAMBDA_CERTIFICATE_DIRECTORY (/certs/apps.example.com/).
  3. Proxy: forward the domain and every subdomain to the server, with the Host header.
  4. Public Suffix List: until the domain is on the Public Suffix List, an app can set a cookie for the whole domain, which browsers then send to every other app. Submit it there.

Each app then answers at https://<public key>.apps.example.com/. Old addresses below /lambda/ redirect to the new ones, and apps.example.com itself shows a page saying what is hosted there. The editor, the APIs, MCP, git and the drafts’ previews stay on LAMBDA_PUBLIC_URL.

Custom domains#

An app in the production or system tier can answer at a domain of its own. Its owner points the domain’s DNS at the server and enters it in the editor’s Domain section (see Domains, showcase and source). Your part is the certificate:

  • With a reverse proxy, add the domain to it, forwarding to the server with the Host header - in Caddy, one more block:

    Caddyfile

    shop.example.com, www.shop.example.com {
        reverse_proxy localhost:8080
    }
    
  • With TLS in the server, issue a certificate into a folder of its own and restart the container, which reads the folder as it starts:

    Shell

    certbot certonly --webroot -w /opt/genhttp-lambda/acme -d shop.example.com -d www.shop.example.com
    
    mkdir -p /opt/genhttp-lambda/certs/shop.example.com
    install -m 0644 -o root -g 1001 /etc/letsencrypt/live/shop.example.com/fullchain.pem /opt/genhttp-lambda/certs/shop.example.com/
    install -m 0640 -o root -g 1001 /etc/letsencrypt/live/shop.example.com/privkey.pem   /opt/genhttp-lambda/certs/shop.example.com/
    

Mind the order: once the owner enters the domain, the app’s old address sends visitors there at once. The server answers certificate challenges for any host whose DNS points at it, so issue the certificate first, then let the owner switch. Leave out www. where its DNS does not point at the server, or certbot fails for both names.