Prebaked
Integration

nginx

Last reviewed

An nginx config sends search engines, AI crawlers and link preview bots to Prebaked, and serves your site to everyone else. Use it when your site runs behind your own nginx, either in front of an app server or serving built files directly. Prebaked errors, outages and slow answers fall back to your site.

How it works

Visitor requests are served as before. Crawler page requests are proxied to Prebaked, which returns the fully rendered page.

  • prebaked-maps.conf (generated from Prebaked's bot list) sets $prebaked_bot for known crawler user agents, $prebaked_ai_bot for AI crawlers and $prebaked_static for static-file paths.
  • prebaked.conf combines them: prerender only GET / HEAD, from a crawler, without an X-Prerender header (Prebaked's own page fetches), not a static file.
  • Crawler requests go to https://service.prebaked.io/<scheme>://<host><path and query> with X-Prerender-Token. HEAD is sent as GET. Only User-Agent, Accept-Encoding, X-Prerender-Token, X-Prerender-Int-Type and X-Forwarded-For are sent (proxy_pass_request_headers off), never the visitor's cookies or credentials. A Set-Cookie from Prebaked is not passed to the crawler.
  • proxy_intercept_errors + error_page: Prebaked 400, 401, 403, 5xx and 508, connection errors (502) and timeouts (504) serve your site. 200, redirects, 404 and 410 reach the crawler.

Prerequisites

  • A Prebaked account with your domain added and verified.
  • Your domain token from the domain's Setup page.
  • Access to the nginx config of your site and permission to reload nginx.

Step 1: Copy the files

curl -o /etc/nginx/prebaked-maps.conf https://prebaked.io/integrations/files/nginx/prebaked-maps.conf
curl -O https://prebaked.io/integrations/files/nginx/prebaked.conf

prebaked-maps.conf holds the crawler and static file maps. prebaked.conf is a complete example (maps, upstreams, one server). Take the parts you need into your config:

  1. In the http context: include /etc/nginx/prebaked-maps.conf;, the three map blocks and upstream prebaked_service.
  2. In your location /: the error_page 418 = @prebaked;, recursive_error_pages on; and if ($prebaked_render) { return 418; } lines, before your existing directives.
  3. In the same server: location @prebaked and location @prebaked_fallback. Put your existing site directives into @prebaked_fallback too.

Replace the placeholders:

Placeholder Value
<your-prebaked-token> Your token
www.<your-domain> Your site

Step 2: Static site (no app server)

If nginx serves your built files directly, use your root and try_files in both places instead of proxy_pass http://site_origin;:

location / {
    error_page 418 = @prebaked;
    recursive_error_pages on;
    if ($prebaked_render) {
        return 418;
    }
    root /var/www/<your-site>/dist;
    try_files $uri /index.html;
}

location @prebaked_fallback {
    root /var/www/<your-site>/dist;
    try_files $uri /index.html;
}

Step 3: Reload and check

nginx -t && nginx -s reload
curl -A "Googlebot" https://www.<your-domain>/        # rendered HTML
curl https://www.<your-domain>/                      # your normal page

Then check which side answered:

curl -sI -A "GPTBot" https://www.<your-domain>/ | grep -i x-prebaked
  • x-prebaked: hit: Prebaked answered from its cache.
  • x-prebaked: stale: Prebaked answered from an older cached copy and refreshes it in the background.
  • x-prebaked: rendered: Prebaked rendered the page for this request.
  • x-prebaked: origin: Prebaked fetched your page itself without rendering it, for example when the render took too long.
  • No output: your site answered directly. The integration is not active yet, the user agent did not match, or the fallback served your page.

The first crawler request appears in the Prebaked dashboard request log.

Test the installation

The curl commands in step 3 show the difference: as Googlebot you get the full HTML, as a visitor your normal page. The first request for a page can take a few seconds while Prebaked renders it; later requests come from the cache. Then run the free checker on the same page.

Markdown requests

Turning it on per domain, choosing pages and testing: Agent-ready responses.

prebaked.conf sends Markdown requests to Prebaked whatever the user agent: a path ending in .md (any case), or an Accept header that lists text/markdown (q=1) without text/html before it at q=1 (*/* alone never selects Markdown; plain nginx cannot compare q values, so an Accept with a fractional q for Markdown takes the normal route). They go out with X-Prebaked-Formats: markdown and the visitor's Accept (location @prebaked_markdown). Markdown off or unavailable (404 or 503 with X-Prebaked-Markdown), Prebaked errors and timeouts go to your site through @prebaked_markdown_fallback, so your own .md files keep working; a crawler that asked by Accept only gets the normal prerendered HTML. A Markdown answer for a page that is itself 404 also goes to your site. The shadow config (prebaked-shadow.conf) does not route Markdown. Check:

curl -sI https://www.<your-domain>/pricing.md
curl -sI -H 'Accept: text/markdown' https://www.<your-domain>/pricing

Test mode

Test Prebaked while your current prerender service keeps answering crawlers. Prebaked does not need your current service's URL or token: in shadow mode requests pass through untouched and only a copy is sent to Prebaked. nginx has no dashboard switch: each mode is a config change and a reload.

Mode Config Crawlers get
shadow prebaked-shadow.conf your current setup. nginx mirrors each crawler request to Prebaked with X-Prebaked-Mode: shadow; Prebaked renders and caches the page and its answer is discarded
ai prebaked.conf with $prebaked_ai_render instead of $prebaked_render in location / Prebaked for AI crawlers (GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-User, PerplexityBot, ...), your current setup for the rest
all prebaked.conf as it is Prebaked

Shadow, in your existing server:

location / {
    mirror /_prebaked_shadow;
    mirror_request_body off;
    # your current setup, unchanged
}

location = /_prebaked_shadow {
    internal;
    if ($prebaked_shadow = 0) {
        return 204;
    }
    proxy_pass https://prebaked_service/$scheme://$host$request_uri;
    proxy_set_header X-Prebaked-Mode shadow;
    proxy_set_header X-Prerender-Token "<your-prebaked-token>";
    # the other proxy_* lines from prebaked-shadow.conf
}

plus the map blocks and upstream prebaked_service from prebaked-shadow.conf in the http context. Only crawler page requests are sent to Prebaked; the mirror location answers everything else itself with an empty 204 that nobody sees.

AI crawlers only: copy prebaked.conf as in step 1, keep your current prerender config in location / and location @prebaked_fallback, and write if ($prebaked_ai_render) instead of if ($prebaked_render).

nginx -t && nginx -s reload

Roll back by putting back the previous config and reloading. Notes:

  • nginx finishes a request only when its mirror copy has finished, so a slow Prebaked answer can keep the crawler's connection busy until the mirror timeouts. That is why the mirror location has short timeouts (proxy_read_timeout 10s).
  • During shadow mode your origin sees about twice the crawler-driven page fetches: one from your current service and one from Prebaked.

Common errors

What you see Cause Fix
nginx -t fails A part of the example is missing, for example the maps include or upstream prebaked_service in the http context Copy all three parts from step 1
Crawlers get your normal page, Prebaked logs a 401 The token placeholder is not replaced, or the token is old Put the current token in X-Prerender-Token and reload
Crawlers get your normal page, Prebaked logs a 403 The domain is not verified yet, or the page URL is sent as http Verify the domain; behind another TLS proxy write https instead of $scheme
Certificate errors to Prebaked The CA bundle path does not exist on your system Set the CA bundle path for your system (see Fallback and security)

More help: Crawlers still see an empty page and 401 and 403 errors.

Fallback and security

Prebaked 400, 401, 403, 5xx and 508 answers, connection errors and timeouts serve your site, so crawlers never see a Prebaked error. Only the headers listed in How it works are sent to Prebaked, never the visitor's cookies.

  • HTTPS to Prebaked with certificate verification (proxy_ssl_verify on, proxy_ssl_verify_depth 4: nginx's default depth 1 rejects the Let's Encrypt chain of service.prebaked.io, and every crawler would get your site). The CA bundle path in the example is the Debian/Ubuntu/Alpine default; adjust it for your system.
  • upstream prebaked_service resolves service.prebaked.io when nginx starts or reloads.
  • proxy_read_timeout 5s is the time between two reads from Prebaked, not a limit on the whole response.
  • The page URL uses nginx's $scheme and $host. If this nginx sits behind another TLS-terminating proxy, $scheme is http: write https instead of $scheme in the proxy_pass line.
  • The visitor IP ($remote_addr) is sent as X-Forwarded-For so Prebaked can verify crawler IPs.

Removing it

Remove the if ($prebaked_render) lines from location /, the @prebaked and @prebaked_fallback locations, the maps include and upstream prebaked_service, then run nginx -t && nginx -s reload.

FAQ

Does this work when nginx serves static files?

Yes. Use your root and try_files in location / and in @prebaked_fallback, as in step 2.

What happens if Prebaked is down?

nginx serves your site. Errors, connection failures and timeouts all fall back to your normal page.

Can I test Prebaked next to my current prerender setup?

Yes. Use the shadow config from Test mode: your current setup keeps answering crawlers and nginx mirrors each crawler request to Prebaked.