Nginx caches the responses in the disk, proxy_cache_path specifies the path where the responses are to be stored. Sometimes, old corrupted cache files may run into performance problems. Deleting faulty cache files can solve these issues.
To clear the cache of NGINX, you need to follow these steps:
1. Connect to your server: Log in to your server using SSH or any other preferred method.
2. Locate the NGINX cache directory: The cache directory can be found in your NGINX configuration. Look for the proxy_cache_path directive in your NGINX configuration file (usually located in /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf). Note down the path specified in the directive.
Example: proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;
In this example, the cache directory is /var/cache/nginx.
3. Clear the cache: Once you have identified the cache directory, you can clear the cache by removing the files within it. Use the following command to delete all the files in the cache directory:
sudo rm -rf /var/cache/nginx/*
This command recursively deletes all files and directories within the cache directory (/var/cache/nginx/ in this example).
4. Restart NGINX: After clearing the cache, you need to restart NGINX for the changes to take effect. Use the following command to restart NGINX:
sudo systemctl restart nginx
Alternatively, you can use the appropriate command for your system if you're not using systemd.
After restarting NGINX, the cache will be cleared, and subsequent requests will fetch fresh content from the server. Remember that clearing the cache may increase the load on your server temporarily as it needs to regenerate the cache for incoming requests.