How to clear the Nginx cache?
Nginx cache clearing needs to be operated according to the configuration method, because there is no built-in clear command. 1. For disk proxy cache, find the path specified by proxy_cache_path (such as /var/cache/nginx), delete the file below and restart Nginx. 2. If the cache clearing function is enabled, you can configure location ~ /purge to achieve specified URL clearing, such as curl -X PURGE to clear a single page. 3. When using FastCGI cache, clear the directory file corresponding to fastcgi_cache_path and restart the service. 4. After clearing, you can use curl -I to check the response header X-Cache: MISS confirms that the cache has expired. The core is to match the configuration path and correctly manage file permissions.
Clearing the Nginx cache depends on how caching is configured. Nginx doesn't have a built-in command to flush the cache, but you can clear it manually or through configuration tweaks. Below are common methods based on typical settings.
1. Clear Disk-Based Proxy Cache
If you're using Nginx as a reverse proxy with proxy_cache , cached files are stored in directories on disk. To clear them:
- Find the cache path defined in your Nginx config (usually in /etc/nginx/nginx.conf or site config):
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;
- Stop Nginx or proceed carefully while it's running to avoid issues:
sudo rm -rf /var/cache/nginx/*
- Restart Nginx to ensure clean state (optional but recommended):
sudo systemctl restart nginx
2. Bypass or Invalidate Specific Cached Content
You can selectively invalidate cache without clearing everything by using cache purging, if enabled.
- Add purge directive in your server block:
location ~ /purge(/.*) {
proxy_cache_purge my_cache $scheme$proxy_host$1;
}
- Purge a specific URL:
curl -X PURGE "http://yoursite.com/page.html"
Make sure only trusted IPs can access the purge location for security.
3. Clear FastCGI Cache (for PHP setups)
If using fastcgi_cache , the process is similar:
- Check the cache path in config:
fastcgi_cache_path /var/cache/nginx-fastcgi levels=1:2 keys_zone=fastcgi:10m;
- Delete cache files:
sudo rm -rf /var/cache/nginx-fastcgi/*
- Restart Nginx:
sudo systemctl restart nginx
4. Verify Cache is Cleared
After clearing, test by requesting a page and checking response headers:
curl -I http://yoursite.com/some-page
Look for X-Cache: MISS or similar header showing content is fetched fresh.
Basically, Nginx cache is file-based, so clearing means removing those files or using a purge mechanism. Just remember to match paths in your config and handle permissions correctly. It's not complex, but easy to misconfigure if paths don't align.
The above is the detailed content of How to clear the Nginx cache?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

1. The first choice for the Laravel MySQL Vue/React combination in the PHP development question and answer community is the first choice for Laravel MySQL Vue/React combination, due to its maturity in the ecosystem and high development efficiency; 2. High performance requires dependence on cache (Redis), database optimization, CDN and asynchronous queues; 3. Security must be done with input filtering, CSRF protection, HTTPS, password encryption and permission control; 4. Money optional advertising, member subscription, rewards, commissions, knowledge payment and other models, the core is to match community tone and user needs.

The core role of Homebrew in the construction of Mac environment is to simplify software installation and management. 1. Homebrew automatically handles dependencies and encapsulates complex compilation and installation processes into simple commands; 2. Provides a unified software package ecosystem to ensure the standardization of software installation location and configuration; 3. Integrates service management functions, and can easily start and stop services through brewservices; 4. Convenient software upgrade and maintenance, and improves system security and functionality.

To solve the problem of inconsistency between PHP environment and production, the core is to use Kubernetes' containerization and orchestration capabilities to achieve environmental consistency. The specific steps are as follows: 1. Build a unified Docker image, including all PHP versions, extensions, dependencies and web server configurations to ensure that the same image is used in development and production; 2. Use Kubernetes' ConfigMap and Secret to manage non-sensitive and sensitive configurations, and achieve flexible switching of different environment configurations through volume mounts or environment variable injection; 3. Ensure application behavior consistency through unified Kubernetes deployment definition files (such as Deployment and Service) and include in version control; 4.

1. The mainstream frameworks of PHP e-commerce backend include Laravel (fast development, strong ecology), Symfony (enterprise-level, stable structure), Yii (excellent performance, suitable for standardized modules); 2. The technology stack needs to be equipped with MySQL Redis cache, RabbitMQ/Kafka message queue, Nginx PHP-FPM, and front-end separation is considered; 3. High concurrency architecture should be layered and modular, database read and write separation/distributed database, accelerated with cache and CDN, asynchronous processing of tasks, sharing of load balancing and Session, gradually microservice, and establish a monitoring and alarm system; 4. Multiple monetization paths include product price difference or platform commission, site advertising, SaaS subscription, customized development and plug-in market, API connection

To configure the PHP environment to support MongoDB, the core step is to install and enable the PHP driver of MongoDB to enable the PHP application to communicate with the MongoDB database. 1. Install MongoDBPHP driver, it is recommended to use PECL to install. If there is no PECL, you need to first install the PHP development package and related compilation tools; 2. Edit the php.ini file and add extension=mongodb.so (or .dll) to enable the extension; 3. Restart the web server or PHP-FPM service to make the configuration take effect; 4. Verify whether the extension is loaded successfully through phpinfo() or php-m. Frequently asked questions include missing PECL commands, compilation errors, php.ini

Effectively managing massive images requires CDN or cloud storage to improve performance and scalability; 2. Optimize file structure through reasonable naming rules and directory storage; 3. Use PHP to automatically compress and convert it into efficient formats such as WebP to reduce volume; 4. Combine front-end responsive images and lazy loading technology to improve loading speed; 5. Realize signature URL anti-theft chain and upload security verification to prevent malicious files, thereby building a safe and efficient picture system to support commercial monetization.

TosetupanNginxserverblock,firstunderstanditsstructureusingtheserverdirectivewithsettingslikelisten,server_name,andlocation;next,createadirectorystructureforyoursitesuchas/var/www/example.com/htmlandsetproperpermissions;thenenabletheserverblockbycreat

Deploying Django applications requires configuration of production environment, Gunicorn and Nginx reverse proxy. 1. Set DEBUG=False, configure ALLOWED_HOSTS, define STATIC_ROOT and run collectstatic to collect static files. 2. Install Gunicorn and test and run it. After confirming that it is correct, manage the service through systemd. 3. Create systemd service file. Configure Gunicorn to start with Unix sockets, set the correct path and enable the service after the user. 4. Install Nginx and create site configuration, specify server_name, configure /static/path to point to the static file directory, and the rest of the requests are passed
