Welcome! Log In Create A New Profile

Advanced

Can nginx do on demand cacheing of static resources by regex

Posted by andrewv 
Can nginx do on demand cacheing of static resources by regex
October 15, 2013 09:58PM
Hi,

My basic setup is nginx on a linux server, proxying requests to a web application running on the same server.

I would like to know if the following can be done with nginx, and if so, how to configure it (I have tried to find this specific combination of features but they don't seem to be there):

1. For the static resources (png's, gifs, some js files, etc) that I want nginx to cache, I would like to be able to specify the URI's that match them in the nginx configuration as one or more regex's, ex. '/mystaticresources/.+\.png$'.

2. If a request is made to nginx for a file that matches any pattern in (1), nginx would firstly check if it has already cached a copy of a file that has a URI which matches the same regex, in it's local cache, and if so, serve up that file, otherwise, pass the original request on to the web application for the file. Once the web application returns the file, nginx would store the file in it's local cache, and so if another request that matched the file was subsequently issued to nginx, then nginx would this time be able to serve up the file from it's local file cache.

This way, the nginx cache would be dynamically added to when the file was first requested, without having to manually populate any of these static resource files as part of setting up the nginx cache. Software upgrades would also be simpler - the cache could be cleared during the upgrade, and static resources that need to be cached would again be cached after first being requested.

Thanks for any advice.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 170
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready