Skip to content
Docs / Install

Set up Pagereckon on an nginx server

Nginx writes an access log for every request it serves, and Pagereckon reads that file to count people, bots and AI crawlers. This guide covers the path, the log format, read access and rotation.

If you run your own server, the whole setup takes about ten minutes. You may need one small change to the nginx config, and only if you want a separate log per site.

The Pagereckon team Updated
Nginx at a glance, from Pagereckon

Where nginx writes the access log

The access_log directive sets the file. The nginx docs give its default as logs/access.log in the combined format, relative to the nginx prefix. Most Linux packages point it to /var/log/nginx/access.log instead.

Many servers also set a separate log in each server block. In that case the file usually carries the site name. The Find my log wizard checks these nginx paths:

  • Per site, dot style: /var/log/nginx/example.com.access.log
  • Per site, dash style: /var/log/nginx/example.com-access.log
  • Short name: /var/log/nginx/example.com.log
  • Shared default: /var/log/nginx/access.log

To find the real path on your server, search the config with grep -r access_log /etc/nginx/. Then use the path from the server block of your WordPress site.

Log formats Pagereckon reads

Pagereckon reads the predefined combined format, the shorter common format and JSON lines. Combined is the best choice, because it includes the referrer and the user agent. Without those two fields, Pagereckon cannot see where visits come from or which bot made a request.

If you use your own format, keep it close to combined. Or switch to JSON with escape=json, which nginx has supported since version 1.11.8. Pagereckon looks for common field names such as these:

nginx.conf, JSON example
log_format pgrk escape=json '{"remote_addr":"$remote_addr","time_local":"$time_local",'
  '"request":"$request","status":"$status",'
  '"http_referer":"$http_referer","http_user_agent":"$http_user_agent"}';
access_log /var/log/nginx/example.com.access.log pgrk;

After a change, test the config with nginx -t and reload nginx. Then new lines use the new format.

Pick the nginx log in Find my log

First, download the free plugin, install it and activate it. Then open Pagereckon, Settings. The Find my log table lists each file PHP can read, with its format and a check mark when the lines belong to your site.

Press Use this log next to the right row. If the file is not listed, paste the path into Test a path. The test reads a short sample of lines, shows the format and hides the IP in the sample. When it passes, enter the path in Access log path(s) and save.

Read access for PHP

PHP-FPM runs as its own user, which is often not the owner of the log. So check the file with ls -l /var/log/nginx/. The PHP user needs read rights, either as owner, through the file's group, or through an ACL.

Also check that the log folder lets that user pass through. If the test still says PHP may not look there, open_basedir in the PHP-FPM pool may block it. Add the log folder to that list, or ask your host to do it.

Rotation and .gz files on nginx

Most systems rotate nginx logs with logrotate. Look in /etc/logrotate.d/nginx to see how often. Typically the live file becomes access.log.1, and older copies end in .gz.

Pagereckon handles rotation on its own. It reads new lines every 10 minutes and notices when a file starts over. In addition, you can import past days with a pattern such as /var/log/nginx/access.log*. Pagereckon reads rotated copies first, oldest first, and each .gz file only once.

However, keep the logrotate create mode in mind. When it makes a new file with tight rights, PHP may lose access after the first rotation. So set the mode and group there, not only on today's file.

Cron and the fallback on nginx

WordPress cron processes the log every 10 minutes, but only when the site gets visits. A server cron is better:

Server cron
*/5 * * * * wp --path=/var/www/example.com pagereckon ingest --max-seconds=240

If the log stays out of reach, switch to the PHP request log in Settings. This mode is less complete: pages served from a page cache, such as the nginx FastCGI cache, never reach PHP, so those views are missing. Behind Cloudflare, also read the Cloudflare guide to keep real visitor IPs in the log, and see how Pagereckon counts AI crawlers.

Nginx questions

Does Pagereckon need a custom nginx log format?

No. The default combined format works. JSON lines work too, as long as they hold the IP, time, request, status, referrer and user agent.

Can Pagereckon read nginx logs in a Docker container?

Yes, if the log file sits on a volume that the WordPress PHP container can read. Then enter that path in Settings.

Does reading the log slow nginx down?

No. Pagereckon reads the file in the background in small steps. Nginx keeps writing as usual.

Sources and references

Free plugin, optional Pro

See your own AI traffic in ten minutes

Install the free plugin, point it at your access log and read today's humans, bots and AI visits. Then add Pro when you want Search Console and the before and after reports.