Serving static versions of dynamic pages (non-RoR)

Jean-Philippe Moal skateinmars at skateinmars.net
Tue Aug 12 03:13:43 MSD 2008


Ian M. Evans a écrit :
> Jean-Philippe Moal wrote:
>> Otherwise you could still create your cache files using the same 
>> layout as your URLs (by creating multiples directories and 
>> subdirectories).
> 
> Ah, I had an brief inkling of that thought last night.
> 
> So I'd have my PHP cache code create different dirs and index files so 
> you'd have
> 
> /galleries/1  => /galleries/1/index.html
> /galleries/1/27  => /galleries/1/27/index.html
> /galleries/1/27/8  => /galleries/1/27/8/index.html
> 
> Since /galleries is actually a FILE in the root, not a directory, could 
> I create a cache dir with a galleries dir elsewhere and say something 
> like this:
> 
> if (-f /cache/$request_filename/index.html)
>     {
>       rewrite ^(.*)$ /cache/$1/index.html break;
>     }
> 
> [No idea if that's the right way to do the syntax]
> 

This should be possible, even without adding a /index.html in the expression 
(nginx should handle this automatically thanks to the index directive).

Note that /cache here refers to a directory directly under the filesystem root.

> Also...is there any magic I'd need to do if someone added a trailing 
> slash so the "if" wouldn't be looking for:
> /galleries/1/27/  => /galleries/1/27//index.html
>                                     ^^

Here again nginx should handle this automatically. At least it does it when 
doing URL processing.

> 
> Thanks for helping me think this through!
> 






More information about the nginx mailing list