How to clear the cache of nginx?
Unless you configured a cache zone via proxy_cache_path and then used it (for example in a location block), via: proxy_cache nothing will get cached.
If you did, however, then according to the author of nginx, simply removing all files from the cache directory is enough.
Simplest way: find /path/to/your/cache -type f -delete
You can also bypass/re-cache on a file by file basis using
proxy_cache_bypass $http_secret_header;
and as a bonus you can return this header to see if you got it from the cache (will return 'HIT') or from the content server (will return 'BYPASS').
add_header X-Cache-Status $upstream_cache_status;
to expire/refresh the cached file, use curl or any rest client to make a request to the cached page.
curl http://abcdomain.com/mypage.html -s -I -H "secret-header:true"
this will return a fresh copy of the item and it will also replace what's in cache.
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