Set Custom Expiry Time for NGINX Reverse Proxy Cache
You can use the following .htaccess rules with NGINX Reverse Proxy to set a custom cache expiration time
<IfModule mod_headers.c>
# Cache everything for 1 minute
<FilesMatch "\.(php|html|htm|js|css|jpg|jpeg|png|gif|webp|svg|ico|woff|woff2|ttf|eot|otf|json)$">
Header set Cache-Control "public, max-age=60"
</FilesMatch>
</IfModule>
You can modify the .htaccess rules according to your specific requirements.
Place the .htaccess file in your domain's document root directory.
You can set custom seconds in max-age as needed.
As shown in the image below, we have set a max-age of 60 seconds. After this time has passed, the cache is considered stale, and NGINX will:
Mark the response with X-Cache-Status: EXPIRED
Revalidate the content by fetching a fresh copy from the origin server
Store the new response in the cache for another 60 seconds

This ensures that the cache is automatically refreshed every minute, keeping content relatively up to date while still improving performance by reducing the number of origin requests.