How to clear the cache of nginx?

Freewind picture Freewind · Jun 4, 2011 · Viewed 373.7k times · Source

I use nginx to as the front server, I have modified the CSS files, but nginx is still serving the old ones.

I have tried to restart nginx, to no success and I have Googled, but not found a valid way to clear it.

Some articles say we can just delete the cache directory: var/cache/nginx, but there is no such directory on my server.

What should I do now?

Answer

Deepan Chakravarthy picture Deepan Chakravarthy · Oct 29, 2012

I had the exact same problem - I was running my nginx in Virtualbox. I did not have caching turned on. But looks like sendfile was set to on in nginx.conf and that was causing the problem. @kolbyjack mentioned it above in the comments.

When I turned off sendfile - it worked fine.

This is because:

Sendfile is used to ‘copy data between one file descriptor and another‘ and apparently has some real trouble when run in a virtual machine environment, or at least when run through Virtualbox. Turning this config off in nginx causes the static file to be served via a different method and your changes will be reflected immediately and without question

It is related to this bug: https://www.virtualbox.org/ticket/12597