Table of Contents
1. Clear Disk-Based Proxy Cache
2. Bypass or Invalidate Specific Cached Content
3. Clear FastCGI Cache (for PHP setups)
4. Verify Cache is Cleared
Home Operation and Maintenance Nginx How to clear the Nginx cache?

How to clear the Nginx cache?

Sep 18, 2025 am 03:33 AM
cache nginx

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.

How to clear the Nginx cache?

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

How to use PHP to develop a Q&A community platform Detailed explanation of PHP interactive community monetization model How to use PHP to develop a Q&A community platform Detailed explanation of PHP interactive community monetization model Jul 23, 2025 pm 07:21 PM

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.

How to build a PHP Nginx environment with MacOS to configure the combination of Nginx and PHP services How to build a PHP Nginx environment with MacOS to configure the combination of Nginx and PHP services Jul 25, 2025 pm 08:24 PM

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.

How to use Kubernetes to keep PHP environment consistent Production and local container configuration standards How to use Kubernetes to keep PHP environment consistent Production and local container configuration standards Jul 25, 2025 pm 06:21 PM

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.

How to use PHP to develop e-commerce backend monetization PHP e-commerce system architecture and profit strategy How to use PHP to develop e-commerce backend monetization PHP e-commerce system architecture and profit strategy Jul 25, 2025 pm 06:33 PM

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

How to configure MongoDB support for PHP environment Settings for PHP connection to Mongo database How to configure MongoDB support for PHP environment Settings for PHP connection to Mongo database Jul 23, 2025 pm 06:54 PM

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

PHP realizes image upload and processing monetization PHP image management and optimization technology PHP realizes image upload and processing monetization PHP image management and optimization technology Jul 25, 2025 pm 06:06 PM

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.

How to set up an Nginx server block (virtual host)? How to set up an Nginx server block (virtual host)? Jul 19, 2025 am 02:00 AM

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

How can I deploy a Django application with Nginx? How can I deploy a Django application with Nginx? Aug 23, 2025 pm 04:26 PM

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

See all articles