简体   繁体   中英

Can nginx serve up files cached by PHP?

As part of a new CMS that I'm planning, I'm going to be caching the HTML output of some "static" content. I say "static" because no content stored in a database is really static, but it's close enough. The system will MD5 hash the request URL and save a minified version of the HTML output in a cache folder. The next time the page is requested, the CMS will check if a cached version exists, then it'll check the age of the file and then serve up the cached version, thus saving a lot of resources (especially when it comes to DB calls).

Obviously getting nginx to serve up static files without going near PHP is going to be much quicker. So is there a way to get nginx to hash the request URL and check a temp folder to see if it exists?

Yes!

You can get nginx to cache the response from the fcgi. It is using the HttpProxyModule that you must have enabled into nginx.

Here is a good guide on how to do it.

Alternatively you can use nginx with memcache too. There are actually quite a few options to you. Both work really well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM