Here is the solution I found so far. As you know there is a command in mod_rewrite which checks if requested file exist. This trick is used by WordPress to process all dynamic requests.
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
We could do something similar. When user makes request, we should calculate MD5 value of URL (within ngnix) and check if file under URL
http://example.com/cache/md5_string exist. If URL does not exist then we should redirect request to PHP script (which will generate that file and store it in cache directory).
I am not sure if we are allowed to have IF statement within ngnix configuration file so let’s simplify the logic. Once we get requests, we calculate MD5 value of URL and redirect user to that new link. This new link will be handled again by ngnix and thus we can check if file under that URL exist (this could be done for sure). If it does not exist then we pass it to PHP script.
The only question I have: how can I generate MD5 value of URL within ngnix? Any solution which requires PHP is not acceptable.
Guys do you have any ideas?