Securing Dokuwiki with nginx

After migrating a server from Apache2.4 to nginx a Dokuwiki install was complaining about the following on the admin page:

Dokuwiki security error with nginx
Dokuwiki security error with nginx

 

Previously .htaccess files were controlling access, which aren’t used by nginx. You can test your Dokuwiki install’s access by attempting to visit the following url:

 

http://yourserver.com/data/pages/wiki/dokuwiki.txt

 

If you can see any content there, you need to fix your permissions. We fixed this by adding the following to the site’s nginx config file (e.g. /etc/nginx/sites-available/sitename):

 

location ~ ^/(data|conf|bin|inc) {
deny all;
}

 

…in the same section as the other “location” stanzas, then restarted nginx (whether the latter is necessary or not I don’t know, force of habit).