# AgentSite — Nginx Install Pattern
<!--
ref: @agentsite/install-nginx
tags: [agentsite, install, nginx, dogfood]
triggers: [installing via nginx, nginx config for agentsite, agentsite owns the byte stream, nginx error_page fallback, how our own marketing site is installed]
trigger_prompt: When installing AgentSite through nginx, or checking how the dogfooded marketing site is configured.
category: reference
complements: [@agentsite/install-patterns]
version: 2
updated_at: 2026-10-24T21:32:04.926Z
-->
The lead install pattern: nginx-only config, AgentSite owns the HTML byte stream via /render path dispatch. The exception to snippet-stays-local.
Fetch this when: installing via nginx; nginx config for agentsite; agentsite owns the byte stream; nginx error_page fallback; how our own marketing site is installed.
Part of [`@agentsite/install-patterns`](@agentsite/install-patterns) — see it for sibling topics.
---
## Nginx pattern — the lead install
**nginx-only install. Customer adds location + proxy_pass directives; agentsite owns the entire HTML byte stream including reach-back for the SPA shell. Renamed from "Pattern F" on 2026-05-17.**
**Naming note (2026-05-17):** Customer-facing docs were renamed from letter patterns (A/B/C/F) to short names (Express / Express-Sidecar / Edge / Nginx). This memo originally lived under "Pattern F" and that label is still all over internal source (`RenderController.ts`, `SiteController.ts`, `SiteRepository.ts`, `SPEC.md`, `workspace/2026-05-16-pattern-f-thin-nginx-spec.md`). Treat **Pattern F == Nginx install pattern**.
The Nginx install pattern is the no-code option for nginx-fronted static SPAs (Lovable / v0 / Bolt self-hosters on a VPS, mid-market shops with an existing nginx tier and no appetite for a Node sidecar). Locked 2026-05-16, spec at `workspace/2026-05-16-pattern-f-thin-nginx-spec.md`.
**Architecture:** Customer's nginx adds a handful of `location` + `proxy_pass` directives. Five path classes (`robots.txt`, `sitemap.xml`, `llms.txt` / `llms-full.txt`, `/.well-known/*`, `*.md`) and the SPA HTML fallback route to `api.agentsite.app/render`. agentsite's `/render` endpoint dispatches by URL path and returns final asset bytes (text/plain robots, application/xml sitemap, text/html for SPA routes after fetching the shell + running `applyBundle` server-side).
**Key backend surfaces:**
- `GET /render?url=<full-url>` — extended to dispatch by URL path. Returns final asset bytes per path class. `Accept: application/json` on HTML paths keeps the legacy JSON bundle for deployed-in-the-wild snippets (back-compat).
- `GET /bundle?url=<full-url>` — new endpoint returning the JSON RenderBundle. In-tree snippets (`@agentsite/express`, `@agentsite/edge`) migrated to call `/bundle`. New code prefers /bundle over `/render` + Accept.
- `site.index_path` column (V50 migration) — per-site SPA shell path override. NULL = default `/index.html`. `SiteService.resolveIndexPath(host)` reads it.
**Trust + safety:**
- Customer's nginx stays the front door. agentsite is just another upstream.
- Loop-prevention is structural: agentsite reaches back to `<host>/<indexPath>`, nginx serves the shell from disk via `try_files $uri @agentsite` and never recurses through us. `X-Agentsite: none` header is the explicit escape hatch for customers whose shell isn't on disk.
- No UA branching, no cloaking (same property as the other shipped patterns).
- Graceful failure via nginx `error_page 502 = @raw_shell` — customer's own nginx serves raw shell if agentsite is unreachable.
**Auth wrinkle for non-public-domain hosts:** `/render` requires `Authorization: Bearer <token>` unless the host is in `RENDER_PUBLIC_DOMAINS` (defaults to `agentsite.app` / `agentsite.com`, exact match — subdomains do NOT match). For real customer hosts, the nginx template must include `proxy_set_header Authorization "Bearer <SITE_TOKEN>";` on every `location` block. Dashboard-rendered config templates this from the customer's site token.
**Nginx footguns — every template MUST include these or installs fail silently:**
1. **`resolver` directive is non-negotiable.** Our `proxy_pass` URLs contain `$host` + `$request_uri` variables, which makes nginx defer DNS to request time. Without `resolver`, every request fails with "no resolver defined to resolve api.agentsite.app" and the site degrades to graceful-failure (200s served, zero enrichment, looks identical to a working install). Default to `resolver 1.1.1.1 8.8.8.8 valid=300s ipv6=off; resolver_timeout 5s;` — substitute the customer's cluster/VPC resolver if known (127.0.0.11 in Docker, kube-dns, AWS VPC).
2. **Hardcode `https://` in the reach-back URL** — do NOT use `$scheme`. Pods behind TLS-terminating ingress see `$scheme = http`, so `$scheme://$host$request_uri` becomes `http://customer.com/...` → triggers the customer's force-ssl-redirect → bonus round-trip + possibly broken render. Use `https://$host$request_uri`.
3. **`proxy_ssl_server_name on;` on every block.** `api.agentsite.app` is multi-tenant TLS; SNI is required for the handshake to pick the right cert. Without it, TLS may fail or return the wrong cert.
These three lines should appear in every template across SKILL.md, INSTALL.md, spec §7 / §13.1, and `devops/pattern-f-test/`. Tripped on the first real customer install (peer project, 2026-05-17). Verified fix in `INSTALL.md` (Nginx section).
**Install surfaces that mention the Nginx pattern (keep them in sync — source of truth is INSTALL.md):**
- `INSTALL.md` (repo root) — **source of truth**, served at `/install.md`. Has the full pattern matrix, decision rule, templates, and Roadmap section.
- `frontend/public/.well-known/agent-skills/install-agentsite/SKILL.md` — **thin pointer** (refactored 2026-05-17 to drop the duplicated matrix; just summarizes when each pattern applies + points at /install.md).
- `backend/src/static/agentsiteDocs.ts` — AGENTSITE_LLMS_TXT, AGENTSITE_DOCS_MD, AGENTSITE_OPENAPI_YAML. Also thinned 2026-05-17.
- `frontend/src/pages/getting-started.vue` — dashboard install tabs.
- `frontend/src/pages/dashboard/[id]/index.vue` — site settings → SPA shell path field.
- `workspace/2026-05-16-pattern-f-thin-nginx-spec.md` — canonical spec (LOCKED 2026-05-16, still uses "Pattern F" naming internally).
- Internal source code (`RenderController.ts`, `SiteController.ts`, `SiteRepository.ts`) — comments still say "Pattern F"; not yet renamed.
**E2E test fixture:** `devops/pattern-f-test/` — docker-compose with nginx + a stub agentsite api + a 4-file SPA + a 20-assertion `test.sh`. Run with `docker compose up -d && ./test.sh && docker compose down`. Directory name still uses the old "pattern-f" label.
## Dogfood — the marketing site runs this pattern
**agentsite.app marketing site itself runs INSTALL.md §3a verbatim (nginx:1.27-alpine). Express snippet dogfood retired. AGENTSITE_TOKEN flows from k8s Secret via NGINX_ENVSUBST_FILTER; env.js generated at boot.**
agentsite.app's own marketing/dashboard frontend dogfoods the Nginx (no-code) install — `devops/docker/frontend.Dockerfile` is now `nginx:1.27-alpine` running INSTALL.md §3a verbatim, byte-equivalent to `demos/after/nginx-container/` (Coastline reference). `frontend/server/` (the Express snippet bootstrap) is deleted.
**Why:** The dogfood originally ran Express for server-side meta injection. The agentsite render service (api.agentsite.app/render) now owns that responsibility end-to-end, so the Express layer was redundant. Switching the dogfood to Nginx (a) live-fires the no-code install path on the marketing site, (b) matches the dev / vibe-coder pitch ("no Node sidecar"), and (c) is a lighter pod.
**How to apply:**
- Before touching `frontend.Dockerfile` / `default.conf.template`, read INSTALL.md §3a + `demos/after/nginx-container/` first. The dogfood mirrors §3a verbatim — keep that property.
- The dogfood-specific addition over §3a is a `/docker-entrypoint.d/40-generate-env-js.sh` hook that writes `/usr/share/nginx/html/env.js` at boot via `devops/docker/generate-env-js.sh`. SPA reads `window.env` for runtime config (`BACKEND_URL`, `POSTHOG_KEY`, `TURNSTILE_SITEKEY`, `BUILD_ID`, `GOOGLE_ID`). Allow-list is in `generate-env-js.sh`.
- `AGENTSITE_TOKEN` is in the k8s Secret (existing). `NGINX_ENVSUBST_FILTER=^AGENTSITE_` is the only `envsubst` scope — must NOT broaden to nginx vars (`$host`, `$uri`, etc. would expand to empty and silently 200-with-no-enrichment).
- Listener / k8s ports: container 80 → service port 80 → ingress 443. Don't reintroduce 3000.
- Smoke test before deploy: `docker run --rm -e AGENTSITE_TOKEN=asit_test <image> cat /etc/nginx/conf.d/default.conf | grep Bearer` should print `Bearer asit_test`. See INSTALL.md §3a failure-mode table for other outputs.
---
*Related: `@protocol/onboarding` · `@protocol/optimizer-install` · `@agentsite/render-outputs` · `@agentsite/platform-conventions` · `@agentsite/project`*
---
*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*
*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*