PHP contact form returns 504 gateway error after moving to Digital Ocean

This one had me scratching my head for a while – using php7.0-fpm and the latest nginx on Debian 8 Jessie I was seeing our PHP contact form working correctly but returning a Gateway 504 error upon submission, which was resulting in a great deal of resubmitted forms and error notifications from users.   This only started occuring after we moved our site to Digital Ocean – it turns out that it was a IP priority issue and the following resolved it:  
vim /etc/gai.conf
  and uncommenting the following line:  
precedence ::ffff:0:0/96  100

Then a reboot. Voila, the contact form worked properly again.

Checking whether nginx cache is working

Just set up nginx caching and wondering whether it’s working properly? You can check it pretty easily:  
curl -I URL.goes.here
That should return a bunch of information, but the important bit is:
X-Proxy-Cache: MISS
  Well, in this case it’s not working. If it’s working you’ll see a HIT there.

Upload error 413 “Request Entity Too Large” on Nginx

When trying to upload files to a Drupal installation running on nginx, we got a 413 error: Request Entity too large.   We had gone through and updated the php files with regard to max upload file size limits, but had neglected to do the same to the nginx config file (/etc/nginx/nginx.conf on Debian). We had to add the following line:
client_max_body_size 20M;
  in the http block and restart the nginx server to get uploads working again. The above will set the limit to 20MB; change it to suit your own environment and needs.   You can also add this to the server or location blocks.

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).