Posts

Showing posts with the label caching

How to fix: Nginx proxy or fastcgi cache always MISS or EXPIRED

Image
I've recently had an issue with my Nginx setup: it wasn't caching or serving cached pages properly. Every time I would visit, I'd get "MISS" or "EXPIRED". What I found online is that you have to instruct Nginx to ignore browser request headers relative to caching, therefore allowing Nginx to determine whether it should serve cache, all by itself. This is done by inserting the following directive: # ignore headers to let Nginx control its own cache fastcgi_ignore_headers Cache-Control Expires; However, I already had this in my configuration and it wasn't helping. After investigating the issue, I determined that my PHP scripts were updating cookies at every request. Nginx was forced to execute the PHP scripts via FastCGI (ie. not serving them from cache) because the cookie data had changed. When PHP sets a cookie, Nginx will not hit the cache, which is normal behavior. I wouldn't recommend changing this behavior. What I di

Setting up and using memcached & memcache on Linux CentOS 5/Plesk 9

Image
The second part of my tutorial on optimizing your server for hosting high traffic websites: installing and configuring memcached and the memcache php extension for your server. This is a little easier than the first step (setting up nginx as reverse proxy, see article below) and can be applied to any kind of dynamic website. What's the point ? On highly dynamic websites such as forums, news sites or any user content based website, the database server load is often very high. The more traffic you get, the more cluttered your database server becomes, sometimes rendering your website completely unavailable to visitors. Using a data caching daemon will allow you to save some data in memory instead of fetching the data from the database every time. You should know that memcached is used by major websites such as Wikipedia, SourceForge, SlashDot... need I say more? What is memcached ? Memcached is the daemon running on your server. Its usage is extremely simple, there are no confi