How to clear cache in Nginx

AiroServer's Blog

How to clear cache in Nginx

There are two general and easy methods to clear the cache in Nginx, which we intend to study together in the following article.

What is cache and what is its use?

When a web server serves a web page, it stores a copy of that web page in its cache, which is call a cache.

This allows the server to quickly serve the same web page to subsequent visitors without having to rebuild it.

Generally, this is because it improves website performance and reduces the load on the server. However, the cache may become outdated over time and you may need to delete it.

How to clear the Nginx cache

Clearing the cache in this web server is done in two ways:

  • Using the command line
  • Manually delete cache files

Clear the Nginx cache using the command line

This method is the easiest way to clear this web server cache. This is possible by using the “nginx -s reload” command.

This command sends a signal to the Nginx main process to reload the configuration and flush the cache. This is useful when you have made changes to your website and want the changes to take effect immediately without waiting for the cache to expire.

Nginx

 

Clear Nginx cache by manual deletion method

Another way to clear this web server cache is to manually delete the cache files.

To delete cache files manually, you must first find the folder where Nginx cache files are store. These files are usually located in the “/var/cache/nginx/” folder.

Once you find the cache folder, you can use the command “rm -rf” to delete all the files and folders inside it.

Of course, you should be very careful when doing this, because this will delete all the cache files and may affect the performance of your website.

Additionally, some Nginx configurations may have a different cache directory location, you can check the nginx.conf file or ask your system administrator where the cache directory is located.

In any case, it is recommended to restart this web server after clearing the cache to make sure the changes are applied. You can do this by using the command “systemctl restart nginx” in the command line.

Finally, clearing this web server cache can done using the command “nginx -s reload” or by manually deleting the cache files.

It is also important to remember that clearing the cache may affect the performance of your website. Therefore, it is always recommend that you make a backup copy of your files before starting.

Note: Before executing any command, make sure you are log in as a superuser or use the sudo command to avoid any permission problems.

Find More Articles...

Whats New?

Baas

Baas

fa_IRFA