Virtualbox caching webserver content forever

Apparently Virtualbox instances don't play well with SendFile, a webserver parameter that defines how the webserver will access files on the filesystem. This parameter defaults to the most optimal for performance which is a good thing. However on Virtualbox VM's this can result in filesystem level caching that prevents any recent changes to files being picked up by the webserver.

It seems like it's a cache that cannot be cleared. I particularly noticed this with css and js files seemingly stuck on a previous revision, with no amount of clearing caches or restarting fixing it.

The cure involved defining the parameter in the apache config on the VM:

SendFile off

Then restarting apache for the changes to shake through.

Note this change is only required for VM environments!

In more recent adventures with Docker I found this issue again. This time either the file did not update or garbage appeared at the end of the file. At first I thought Docker would be immune from the sendfile issue but wait - Virtualbox is providing the base docker machine (I'm using macOS) so it's the same situation!

This time nginx was the webserver. In this case amending the virtualhost file and restarting nginx sorted the issue.

# /etc/nginx/nginx.conf

http {

    # Basic Settings
    sendfile off;

    # Existing config

Tags: apache, nginx, virtualbox