Skip to content
RU
← All articles

AI Bots in nginx Access Logs: JSON and jq

Quick answer

Identify AI crawler candidates in nginx access logs by matching product names in the User-Agent field, then break down the results by agent and response status. Keep training crawlers, search crawlers, and user-triggered fetchers in separate groups. If identity matters, verify candidates against the operator’s documentation and addresses at your trusted edge.

Engineer reviewing nginx request logs at a workstation
A structured log keeps the agent name and status in separate fields.

Choose the log that can answer your question

Start at the point that served the response. For a Cloudflare-backed site, an origin-only sample covers requests that reached nginx. The edge can serve cached HTML and can reject traffic before a request ever reaches the server. Use edge logs to ask what visitors received. Use origin logs to ask what reached the application or nginx. Compare matching time windows before trying to explain a discrepancy.

Define the unit as requests. One crawler can fetch the robots file, follow a redirect, request a page and return later. Each logged request adds a row. For a rollout check, choose a hostname and a time range in UTC, then decide whether you want every request or just public document routes. Retain that definition alongside the report so the next on-call engineer can rerun it.

Step 1. Add a narrow JSON log

Keep the request path and status alongside time and the client-reported User-Agent in separate fields. The default combined log puts request target, referrer, and User-Agent on the same line. Searching all fields for a bot name can count a human visiting a URL that contains the name. A structured log also makes it easier to avoid copying cookies, referrers, raw addresses, or query parameters into a crawling report.

log_format crawl_json escape=json
    '{"time":"$time_iso8601","status":$status,'
    '"path":"$uri","ua":"$http_user_agent"}';

access_log /var/log/nginx/crawl.jsonl crawl_json;

Declare log_format under http. The sample places access_log there too. On a shared instance, scope the new log to the relevant virtual host and preserve your existing access logs. Check locations with their own logging configuration. The nginx log module documentation explains how multiple directives work at one level and where an internally redirected request ends up being logged.

The JSON escaping option keeps embedded quotes and control characters parseable. The $uri value is the current normalized path, which may change during request handling. For example, a front controller can change the logged path during an internal rewrite. Verify the path you see on your own sample before building a dashboard grouped by endpoint. Avoid switching to the full original request target without considering what your URL parameters carry.

Step 2. Count candidate requests by user agent and status

Copy the following filter to report.jq. The reducer streams newline-delimited JSON and keeps a small set of counters. The expression requires a boundary around the product token so a longer name such as ExampleNotGPTBot stays out of the count. It accepts a version suffix, lowercases the matched product name, and uses the first recognized token per row.

reduce inputs as $row (
  {total: 0, candidates: 0, by_agent: {}};
  .total += 1
  | ([$row.ua | match(
      "(?:^|[ (;])(?<agent>GPTBot|OAI-SearchBot|ClaudeBot|PerplexityBot|ChatGPT-User|Claude-SearchBot|Claude-User|Perplexity-User)(?:[/ );]|$)";
      "i"
    ).captures[0].string | ascii_downcase][0]) as $agent
  | if $agent == null then . else
      .candidates += 1
      | .by_agent[$agent][($row.status | tostring)] += 1
    end
)
jq -n -f report.jq sample.jsonl

The fixture contains seven requests. Five match the filter. The ClaudeBot row lands under status 301. The GPTBot row lands under 200, but its path is /robots.txt. A crawler dashboard that rolls both values into a single “successful crawl” figure hides the difference between a fetched policy file and a fetched document. Build a separate view for public pages if that distinction matters to your team.

Use the official agent names as the reporting keys. OpenAI’s crawler reference describes the distinct roles of OAI-SearchBot, GPTBot, and ChatGPT-User. Anthropic’s reference distinguishes Claude-SearchBot, ClaudeBot, and Claude-User. Perplexity’s reference distinguishes its search crawler from user-directed requests. The list in the filter covers these agents and can be revised as their published documentation changes.

Two request groups branch from a server log
Track robots.txt requests separately from documents.

Step 3. Investigate the status family before changing rules

Pull the path and time for failed requests. A 301 tells you to inspect the target and final status. A 403 calls for checking which layer made the decision. Distinguish a firewall rule at the edge from authorization inside the application. A 429 calls for checking when the limit was hit. For an origin-side 5xx, correlate the request with the application log and see whether ordinary clients on the same route also failed. Use the 5xx troubleshooting guide to narrow down the layer.

Use a time series when you need to understand a release. A quiet report from a single hour can reflect crawl timing. A daily status breakdown with the affected routes is more informative than a single lifetime total. Track the covered vhost, interval, exclusions, and any gap from log rotation or CDN export. If those inputs change, call it out before comparing the current count with the previous period.

Keep identity verification as a second step. HTTP clients supply their own User-Agent strings. Use the real client address available at your trusted edge and the operator’s published verification procedure when the distinction will affect a decision. For OpenAI, choose the range list for the specific agent. See the GPTBot IP verification guide for how a range check works.

Save counts that another engineer can reproduce

Export absolute request counts alongside the candidate share. For the fixture the share is 5 of 7. Call that figure the share of rows with a matching User-Agent. If a dashboard needs the share of verified requests, compute it as a separate metric with its own verification rules. Record coverage gaps for the interval because a missing rotated file can change the denominator.

For redirect incidents, keep the original logged path and compare it with the destination in the redirect chain checker. A separate count of document requests helps a reviewer see whether a change affected crawls to actual content.

Verify the report with a known sample

Use a small set of known routes and statuses to confirm the logging setup, then review the resulting rows. For public policy checks, use AI Readiness and the robots.txt checker. These checks help explain what a crawler is allowed to request. The status breakdown shows what the logging layer actually served.

Observed resultNext check
Only robots.txt has a 200Look for document routes in the same period.
Origin activity dropped after a cache changeCompare edge and origin logs with matching time windows.
More than one agent name in a rowReview the raw field. The example keeps the first recognized name.
More 403 responses after a rule changeCompare timestamps against the edge and application rule logs.
Parser stops at a lineCheck for malformed JSON, mixed log formats, or an incomplete rotated file.

How we tested the examples

We checked the configuration syntax with nginx 1.26.3 using a temporary log path. We ran the jq reducer against seven synthetic records with known status codes and checked the expected counts. The fixture demonstrates how the parser treats paths and versions as well as a lookalike product name. It does not estimate bot share on Enterno or validate ownership of any client address.

For crawler roles and differences between fetched and rendered HTML, see how AI crawlers read your website.

Frequently asked questions

Can I use this on a combined access log?

Use a parser for your actual format and extract the User-Agent field first. This jq example expects newline-delimited JSON, with a string field named ua.

Can I combine crawler requests and user fetches?

You can sum requests to estimate traffic load on a server. For reports about training or search discovery, retain a breakdown by product so each row keeps its meaning.

How do I connect bot requests to visits from ChatGPT?

Measure the two separately. Access logs record HTTP requests. A session analytics report uses source attribution from referral and campaign signals, and needs a working analytics tag to observe page activity.

Sources

Check your website right now

Audit your site's SEO →
More articles: SEO
SEO
robots.txt Guide: Syntax, Rules, Testing and Ready-Made Files
16.03.2026 · 1 191 views
SEO
Sitemap XML: Structure, Limits, Generation and Validation
16.03.2026 · 1 130 views
SEO
Open Graph Tags: Control Link Previews in Telegram and X
21.07.2026 · 954 views
SEO
Website Migration Checklist: Avoid SEO and Downtime Pitfalls
16.03.2026 · 840 views