How to make statistics and permalinks work with WordPress and Nginx

Nginx is a high performance web server used as an alternative to the popular Apache web server. WordPress works great on Nginx machines, however you need to adjust some files to get site statistics to work as they would on an Apache server.

This article shows you how to view your Analog stats after enabling stats in your DreamHost panel.

WordPress stats and Apache

Site statistics are not initially available when running WordPress. When WordPress is running on an Apache server, you can use an .htaccess file to allow the /stats subdirectory to serve your site statistics. View the following article for details:

WordPress stats and Nginx

After making any adjustments to a .conf file, you must restart your VPS or reload your Dedicated server.

When using Nginx, your .htaccess file does not function. So you must add code to another file in order to view your stats. Your Nginx WordPress site has two directories:

Your actual web directory (aka document root)

/home/username/example.com

Your nginx/example.com directory where ALL config files should be placed

/home/username/nginx/example.com

View the Nginx configuration file locations article for further details.

In this /home/username/nginx/example.com directory, create a file titled wordpress.conf. Add the following rule at the very beginning of this wordpress.conf file.

### stats
	if ($request_uri ~* ^/(stats|failed_auth\.html).*$)
{
	break;
}

Now when you visit example.com/stats, a login prompt displays allowing you to log in and view your site statistics.

Enabling stats and permalinks

WordPress uses something called 'permalinks' to make the URLs easier to read. When running Nginx, add the following two sections to get both site statistics and permalinks to function.

### stats
if ($request_uri ~* ^/(stats|doc|failed_auth\.html).*$)
{
	break;
}
### Permalinks
if (!-e $request_filename) {
  rewrite ^.*$ /index.php last;
}

Troubleshooting

If you've enabled a stats user on the (Panel > 'Domains' > 'Site Statistics') page but find stats are still not accessible, please contact DreamHost support.

See also

Did this article answer your questions?

Article last updated .