Solving caching issues with Vagrant on vboxsf

Vagrant logo

Since some months I’ve been working with Vagrant as a tool for provisioning my production-like environment to develop Opennemas. Vagrant is a really powerful tool for automating the creation of environment that mimic your production stack without having to deal with configuration files.

In fact this task, automatic provisioning machines, was one of the most important tasks in order to reduce our technical debt. But anyway, let’s move to the topic of this article.

We use Ubuntu OS as a guest VM provisioned by Vagrant+Virtualbox and we share our project code with the guest machine through vboxsf. Inside that machine, among the rest of the stack, it’s running Nginx (but this issue will be present regardless the web server you are running).

The problem

If you have a Linux guest OS, and your web server document root is in a shared folder using vboxsf, after modifying a static file of that folder from outside of the virtual machine you will see that those changes will not be applied, instead of that you will see a bunch of weird symbols accompanied of zero-length responses to non-zero-sized files.

The solution

This issue is due to a partial implementation of the vbox file system and how web servers interact with the  guest file system. So if you want to solve this issue you have to add to your virtualhost configuration files the next directive:

For nginx:

sendfile off;

For Apache:

EnableSendfile off

The explanation

Quite weird and annoying issue. I spent some time digging into the configuration files of my vagrant setup, nginx server, host file system, reviewing browser cache, … and finally I found some links that helped me to solve the issue (see them below).

The problem is that the server serving the static files is using the “sendfile()” syscall, which is broken with the VirtualBox file system. You need to disable sendfile() usage in your server.

References: