Clear NGINX Cache in WHM: Step-by-Step Guide
In this article
Clearing the NGINX cache in WHM (WebHost Manager) removes stored versions of website content that may be outdated or incorrect, ensuring users see the most recent version of a site. This is essential after updates to CSS, JavaScript, or content that isn’t immediately visible due to caching. Since WHM doesn’t directly manage NGINX cache in all configurations, success depends on how NGINX is integrated—typically via third-party plugins like NGINX Proxy Manager, EasyApache 4 with mod_proxy, or custom server setups. This guide walks through identifying and clearing NGINX cache when WHM is used to manage a cPanel server with NGINX in front of Apache.
What You'll Need
- Root or administrative access to WHM
- SSH access to the server (command line)
- Knowledge of whether NGINX is running as a reverse proxy
- Location of NGINX cache directory (often
/var/cache/nginx) - Basic familiarity with Linux command line
- Confirmation that NGINX is actively caching (check configuration files)
Step-by-Step
- Log in to WHM using your administrative credentials. Navigate to the main dashboard.
- Determine if NGINX is configured as a reverse proxy. Go to Home > Software > Service Configuration > Service Manager. Look for NGINX or nginx-proxy in the list. If it’s not listed, NGINX may not be active.
- If NGINX is managed via a plugin (e.g., NginxCP, nginx-manager, or EasyApache 4 with mod_remoteip), check the plugin’s interface in WHM for a cache-clearing option. Some plugins include a “Purge All Cache” button.
- Access the server via SSH as root. Use a terminal or SSH client to connect to your server IP.
- Check if NGINX caching is enabled by viewing the configuration file. Run:
cat /etc/nginx/nginx.conf
Look forproxy_cache_pathdirectives. If present, caching is active. - Identify the cache path. The
proxy_cache_pathline will specify a directory, commonly/var/cache/nginx. Note this path. - Stop NGINX temporarily to prevent file locks during cache deletion. Run:
systemctl stop nginx
Wait a few seconds for the service to shut down completely. - Delete the cache files using the
rmcommand. Replace the path if different:rm -rf /var/cache/nginx/*
This removes all cached files but preserves the directory structure. - Restart NGINX to begin fresh caching:
systemctl start nginx
Verify it’s running with:systemctl status nginx - Test the website in a browser. Open an incognito window and visit a page that was recently updated. Confirm new content appears.
- (Optional) If using a control panel plugin, log back into WHM and verify no errors appear in the NGINX or proxy service status.
- (Optional) Monitor the cache directory to confirm new files are being created:
ls -la /var/cache/nginx
After a few visits, subdirectories and cache files should reappear.
Common Mistakes
One frequent error is assuming WHM has a built-in NGINX cache purge tool. Most WHM installations do not include this unless a third-party plugin is installed. Another mistake is deleting the entire cache directory instead of its contents, which can break NGINX if the path is not recreated. Skipping the service stop step can lead to incomplete deletions due to file locks. Some administrators run rm -rf /var/cache/nginx instead of /var/cache/nginx/*, which removes the parent directory and requires manual recreation with correct permissions. Also, failing to verify that NGINX is actually caching leads to unnecessary steps—some servers run NGINX without caching enabled.
Tips
Always back up the NGINX configuration file before making changes. Use cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak to create a backup. If your server uses a custom cache path, double-check it in the config file before deletion. Use the find command to locate cache files if unsure:find /var -name "nginx" -type d 2>/dev/null
This searches for directories named nginx under /var. Consider setting up a cron job or script to automate periodic cache clearing if updates are frequent. Also, inform users or schedule cache clears during low-traffic periods to minimize impact.
Troubleshooting
If the cache doesn’t clear, first verify that NGINX was actually stopped before deletion. Run ps aux | grep nginx to check for running processes. If NGINX is still active, use kill or systemctl stop nginx again. If the service fails to restart, check logs with:journalctl -u nginx --since "5 minutes ago"
Common issues include incorrect directory permissions or a missing cache path. If /var/cache/nginx was deleted entirely, recreate it:mkdir -p /var/cache/nginx
Then set proper ownership:chown nginx:nginx /var/cache/nginx
Ensure the proxy_cache_path in nginx.conf matches the actual directory. If caching still doesn’t work, validate the config with:nginx -t
This checks for syntax errors. If the site loads but cache isn’t updating, confirm that proxy_cache is enabled in server blocks and that cache keys are properly defined.
Frequently Asked Questions
Does WHM have a built-in NGINX cache clear option?
No, WHM does not natively include an NGINX cache purge tool unless a third-party plugin is installed. Most clearing must be done via command line.
Will clearing NGINX cache affect website performance?
Temporarily, yes. After clearing, NGINX must rebuild the cache, which may slow initial page loads until popular content is re-cached.
Can I clear cache for just one website?
Yes, if the cache uses separate zones or subdirectories per site. You’ll need to identify the specific cache key or path in the configuration and delete only that subset.
Is it safe to delete NGINX cache files?
Yes, cache files are temporary. Deleting them forces NGINX to fetch fresh content, but ensure NGINX is stopped during deletion to avoid corruption.
How often should I clear NGINX cache?
Only when necessary—after major content or design updates. Routine clearing is not recommended as it defeats the purpose of caching.
What if NGINX isn’t installed on my cPanel server?
Many cPanel servers use Apache only. If NGINX isn’t present, caching may be handled by other systems like LiteSpeed, Varnish, or browser cache only.