Clear nginx Cache in Vagrant

45 thoughts on “Clear nginx Cache in Vagrant”

  1. Thank you for this. I won’t say the wall doesn’t have any head-sized impressions, but you saved it from many more.

  2. Omigod. This page saved me *again*! Just now! Thank you!

    I’ll probably never forget that sendfile thing now, it will spring first thing to my mind the moment I see weird errors that have no explanation.

  3. Since a lot of people are probably coming here through the Varying Vagrant Vagrants repository, and it looks like sendfile is now off by default in that project, you may sleep easy: If you’re relying on Varying Vagrant Vagrants for your local development environment setup, this should no longer be a problem if you’re running the latest version!

  4. Thank you! I’ve spent forever trying to sort this out – disabled all caching in nginx and even re-provisioned by vagrant box. What a strange issue.

  5. With the risk of sounding like spam: This was the best blog post I’ve read in a long time. You just saved me many hours and most of my hair. Thanks. Thought I was going crazy. :)

  6. I’m sorry if you think this is thank-you spam. But i must do it: From my soul, a sincerest THANK YOU. I was really about to crash my laptop into pieces. THANK YOU, good soul.

  7. I’ll add another thanks for this post. Fortunately I found it rather quickly after using curl and verifying that nginx served the CSS files oddly, while going directly to Laravel worked fine.

  8. It worked for me! Thank you
    I tried several search terms to find a solution to this misery!

    By: Google Translate

  9. Hello,

    I am using NGINX 1.6.0-1, I turned off the sendfile option, also turned off the browser’s cache but the files continue to be served from the cache even after restarting NGINX and deleting the whole cache directory.

    Any help would be appreciated.


    1. Hi Migual,

      I had the same problem, even after a vagrant halt;vagrant up, but as soon as I changed the cached file (just creating a new line will do), it worked!

      I guess the cache isn’t just in the location you thought, and it may still keep using it until there are changes on disk. Very odd behaviour!

  10. Thanks, I love you!!!! After hours of troubleshooting this is what it was. I’ve been testing out Docker and was almost convinced something was up with the container

  11. Thank you Jeremy! I was fighting with this problem half a day. You article has save a lot of my time!
    In case someone has apache instead of nginx: “EnableSendFile” is responsible for handle sendfile feature. In openSUSE for example it’s located in /etc/apache2/server-tuning.conf

  12. Running version nginx 1.4.6 and sendfile off is not fixing the issue for me. I restarted nginx – nothing, then restarted vagrant – nothing, modified cached file – nothing.
    My application is located in directory mounted by vagrant from OSX and not physically located in vagrant. Maybe this is causing the issue. When I serve application with uwsgi it is all fine, the moment I give control to nginx then I get corrupted files.

      1. There is one main config at /etc/nginx/nginx.conf where i use “sendfile off;”. This config includes app specific configuration (there’s only one). I tried also placing “sendfile off” in app configuration file within server {} section but this didn’t help either.

        1. I had the same problem as you Marcin (setting sendfile to ‘off’ did not fix the problem). You are correct that it has something to do with vagrant’s mounting of the application folder. I had the same setup and debugged for 3-4 hours only to realize that this problem happens when i edit the application files from the host (when i edit within vagrant’s vm it is totally fine).

          Then i googled around for solutions for mounting the NFS correctly. I found this configuration (for Vagrantfile) works with editing application files from the host computer:

          config.vm.synced_folder “./”, “/vagrant”, type: “nfs”, mount_options: [“nolock”, “vers=3”, “tcp”]

  13. from where i can found my NGix.conf file. i use vagrant and centos 6.5 Virtaul mechine i m not able to find such file. please help me

  14. Thanks this worked for me :)

    P.S To reflect the changes after setting sendfile off, just service ngnix restart did not work for me.
    Make sure you due vagrant halt and then restart it using vagrant up.


Leave a Reply