How to delete/clear Nginx cache ?

clear-nginx-cache

Nginx is a powerful webserver which can act as a reverse proxy for caching static pages. Keeping Nginx in the frontend will reduce the load on the backend servers as frequent requests will be served by Nginx cache. In this article we will see how to clear Nginx cache. 

1. Clear Nginx Proxy cache

Nginx cache the responses from Backend in the cache folder, by default it is “/var/nginx/cache/”

You can clear nginx cache by deleting the files under “/var/nginx/cache/”

There is no need to restart nginx server after this. Make sure you are NOT deleting the “cache” folder itself. 

2. Cleaning the browser cache by header input

Whenever nginx serves static contents, browsers store this responses in its cache. Let us see how to force browser to invalidate the cached files after x number of days

Add the above config block in the nginx configuration. By this browser will invalidate the cache after 1 day  and fetch the content from the server. This is helpful when we modify the content often on your website.  

Restart nginx webserver after making the above changes.

Or Using systemctl

 

3. Disable “sendfile”

When you use nginx webserver to serve locally stored static files, sendfile is totally essential to speed your Web server. But when you use it as app server to serve dynamic requests using fcgi or as a proxy server, keep it disabled

SUMMARY

In this article we explained how to clear nginx cache at different stages, on server and in the browser.

As always, feel free to drop us a note if you have any questions or feedback using our comment form below. Always Happy to help ???? 

One thought on “How to delete/clear Nginx cache ?

  • August 17, 2017 at 11:51 pm
    Permalink

    How Nginx clears the old cache by itself? I still can see lot of old cache data in the system.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *