Vagrant logo

Solving caching issues with Vagrant on vboxsf

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.


  • Nice one. That had to be hard to catch. I’ll keep it in mind, just in case I ever find myself facing the same kind of issues.

  • Jesse Griffis

    THANK YOU. Good grief. The trouble is it’s not every file, but when it hits there’s no saving it. Thank you for posting this.

  • Pingback: Vagrant ve Önbellekleme Sorunu | Ömer ÜCEL()

  • Thank you very much! :D

  • Vladas

    Thank you! I had already been considering putting “echo 3 > /proc/sys/vm/drop_caches” on while loop, just before i found your post… This one was hard to catch…

  • Better solution: Switch Vagrant to NFS

  • Not possible if you are using eCryptFS for your home folder and you keep your code inside there.

    Now I’m using full-disk encryption and I can use NFS which provides a huge performance boost.

  • Lifesaver!!! Thank you! It took us couple days to find out!