Lightning Fast WordPress with Nginx + Redis

通过配置Redis作为前端缓存,显著提升了WordPress网站的加载速度。页面加载时间从0.2到1.2秒减少到了平均0.0025秒。本文提供了一套详细的安装指南,包括所需软件和步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I had the good opportunity of ending up on Jim Westgren’s article about using Redis as a front end cache and it didn’t take long for me to try it on one of my virtual boxes. The results were unbelievable, pages that were taking about 0.2 to 1.2 seconds were now loading at 0.0025 second on average.

Unfortunately, Jim is a bit busy showing us how he configured his server to run on nginx + php-fpm + apc + cloudflare + redis. So in doing my share to make (a part of) the web faster and better for everyone here’s an install guide to get you started.

What You Need

A virtual private server (VPS), this unfortunately is required. If you are in a shared hosting environment, sorry but this isn’t for you. If you want to jump in managing your own VPS, I highly recommend DigitalOcean, cheapest and fastest that I’ve known so far, the one I currently use for all my sites.

The following applications, nginx, php-fpm, redis and predis, a flexible php client library for redis.

Finally, at least a very basic knowledge in using linux based systems. I prefer using CentOS and the server that this blog is on is using this distro.

Setting up Redis

If you’ve got all three covered, let’s get started. This redis config works well with this centos + nginx + php-fpm installation in a vps. Install nginx and php-fpm, make sure it’s configured properly to run WordPress.

Install redis on your server, here’s a clean and easy to follow guide for installing redis on CentOS. Make sure Redis is running on your server before continuing.

Setup a WordPress blog on your vps. While I don’t have a good guide yet based on my setup, I recommend you read this guide to get you started.

Installing WP Index Redis

Please download wp-index-redis.php, you’ll need this to interface WP with Redis.

I really don’t have a name for this script but, I’ll just call it it WP Index Redis for now. I’ve made a lot of changes to the script that Jim originally created but here are the main difference:

  • Pages are not cached when you are logged in.
  • Cached pages do not expire not unless explicitly deleted or reset (deleting the entire domain cache).
  • Appending a ?c=y (e.g. domain.com/?c=y) to a url deletes the entire cache of the domain. Only works when you are logged in.
  • Appending a ?r=y to a url deletes the cache of that url.
  • Refreshing (F5) a page deletes the cache of that page.
  • Script still works even if allow_fopen is disabled in php.
  • Submitting a comment deletes the cache of that page.
  • Includes a debug mode, stats are displayed at the bottom most part after </html>. Won’t be deleted by CloudFlare.

Like always, use this at your own risk. Be comforted though that I use this myself on this very blog. So on to installing the redis cache interface:

Edit wp-index-redis.php and change some variables where appropriate. The default should work out of the box, but if you are using CloudFlare set $cf = 1, and if you’d like to see some cache generation times set $debug = 1. Otherwise leave everything as it is.

Upload wp-index-redis.php on your WP blog. Make sure you upload this where your main WordPress index.php resides.

Do the same for predis.php.

Rename the WordPress index.php to _index.php or any name that will indicate that this is the original index.php.

Rename wp-index-redis.php to index.php. That’s it you are all set.

Open your browser and access your site, if you’ve enabled debug, you should see some page execution status and figures at the bottom most part of each WordPress page.

For the curious, this blog is on CentOS with nginx + php-fpm + mysql + redis. I didn’t bother (for now) to install apc or xcache because I believe in the mantra, less is more. In the very near future I should be able to publish a guide on how I’ve setup my vps.

If nothing broke on your site, you can breathe now, congratulate yourself and let your neighbor know that your level of geek has just plus-oned (+1) today. ^_^


http://www.jeedo.net/lightning-fast-wordpress-with-nginx-redis/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值