Skip to content

nginx

An nginx config that proxies crawler requests to Prebaked and serves your site to everyone else. Prebaked errors, outages and timeouts fall back to your site.

nginx sends crawler requests (search engines, AI crawlers, link previews) to Prebaked and everything else to your site. Prebaked errors, outages and slow answers fall back to your site.

What it does

  • prebaked-maps.conf (generated from Prebaked's bot list) sets $prebaked_bot for known crawler user agents 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.

1. Copy the files

sh
cp prebaked-maps.conf /etc/nginx/prebaked-maps.conf

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:

PlaceholderValue
<your-prebaked-token>Your token
www.<your-domain>Your site

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;:

nginx
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;
}

3. Reload and check

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

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

Notes

  • HTTPS to Prebaked with certificate verification (proxy_ssl_verify on). 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.

Start a 30-day free trial.

No card needed. Add and verify your domain, copy your token, paste it into the config above.

Start free trial