When a web server serves a webpage, it stores a copy of the webpage in its cache. This allows the server to quickly serve the same webpage to subsequent visitors without having to regenerate it. This improves the performance of the website and reduces the load on the server. However, over time, the cache can become outdated, and it may be necessary to clear it.
Clearing the cache of Nginx web server can be done in two ways: using the command line or manually deleting the cache files.
Using the command line
The most convenient way to clear the cache of Nginx web server is by using the command “nginx -s reload”. This command sends a signal to the Nginx master process to reload the configuration and clear the cache. This is useful when you have made changes to your website, and you want the changes to take effect immediately without waiting for the cache to expire.
nginx -s reload
Manually deleting cache files
Another way to clear the cache of Nginx web server is by manually deleting the cache files. Nginx stores the cache files in the “/var/cache/nginx/” folder. This folder contains subfolders for each website, and inside each subfolder, there are files that represent the cached pages. By deleting these files, you can clear the cache of a specific website. However, be aware that this method will delete all cache files and may affect the performance of your website.
To manually delete cache files, first, you need to locate the folder where the Nginx cache files are stored. These files are usually located in the “/var/cache/nginx/” folder.
ls /var/cache/nginx/
Once you have located the cache folder, you can use the command “rm -rf” to delete all the files and folders inside it. Be careful when doing this, as it will delete all cache files and may affect the performance of your website.
rm -rf /var/cache/nginx/*
Additionally, some Nginx configurations may have different cache directory location, you can check nginx.conf file or ask your system administrator where the cache directory located.
In any case, after clearing the cache, it is recommended to restart the Nginx web server to ensure that the changes take effect. You can do this by using the command “systemctl restart nginx” on the command line.
systemctl restart nginx
In conclusion, clearing the cache of Nginx web server can be done by using the command “nginx -s reload” or by manually deleting the cache files. It’s important to keep in mind that clearing the cache may affect the performance of your website. Therefore, it is always recommended to take a backup of your files before starting.
Note: Before you execute any command make sure you’re logged in as a superuser or use ‘sudo’ command to avoid any permission issues.