最近,在一台测试服务器上,安装了多个 WordPress 网站。为了优化性能,提升加载速度,先在宝塔上安装了 Redis,然后在 WordPress 后台安装了 Redis Object Cache 插件。

现象描述:
① 在 A 网站上启用 Redis 后一切正常。
② 当在 B 网站上启用后,B 网站出现白屏问题。
③ 然后继续在其他网站上启用,有的出现了白屏问题。还有的出现了文章列表展现其他网站网站文章的问题。
④ 当尝试登录网站后台时,网站异常跳转至 A 网站登录地址。
通过百度和谷歌搜索了解,网上有各种各样的解决方案,现列举如下:
方法一:安装 WordPress 时设置唯一的数据库表前缀
在安装 WordPress 时,在填写数据库凭据信息时,“Table Prefix”项默认为 wp_,将其设置为一个唯一的值,这样就可以避免在启用 Redis 时,出现网站数据串站和白屏问题。
因为服务器上已安装了多个网站,所以并未采用更改数据库表前缀的方法。如果大家是新安装的 WordPress 网站,建议将每个网站的表前缀设置为一个唯一的值。
方法二:为每个网站定义 WP_CACHE_KEY_SALT
在每个 WordPress 网站的根目录下,都有一个名为 wp-config.php 的核心配置文件。我们可以在该文件中为每个网站设置一个 WP_CACHE_KEY_SALT 值。这样,就可以避免在多个网站启用 Redis 后,出现数据串站或者异常跳转问题。
define( 'WP_CACHE_KEY_SALT', 'yourdomain.com' );
将 yourdomain.com 替换成每个网站的域名,然后把上面的代码添加到下面注释的上方。
/* That's all, stop editing! Happy publishing. */
方法三:修改 Redis Object Cache 缓存插件配置文件
WordPress 网站一般使用 Redis Object Cache 插件,来管理 Redis 对象缓存。该插件的配置文件位置如下:
/wp-content/plugins/redis-cache/includes/object-cache.php
打开该配置文件后,找到如下所示的位置。默认情况下,每个网站定义的 ‘database’的值都是 0 ,我们可以为每个网站配置 0-15 之间的不同值。

如果修改完成后,白屏和数据串站问题仍然没有解决,可以尝试重新启用服务器。
最新评论
Hey! I could have sworn I've been to this blog before but after checking through some of the post I realized it's new to me. Anyways, I'm definitely delighted I found it and I'll be book-marking and checking back often!
Heya i am for the primary time here. I came across this board and I to find It really helpful & it helped me out much. I'm hoping to give something back and help others like you helped me.
Pretty element of content. I simply stumbled upon your website and in accession capital to claim that I acquire in fact enjoyed account your weblog posts. Any way I’ll be subscribing for your augment and even I success you access persistently rapidly.
Would love to perpetually get updated outstanding weblog! .
Some really nice stuff on this internet site, I like it.
Can I simply say what a reduction to find somebody who actually knows what theyre talking about on the internet. You positively know find out how to carry an issue to mild and make it important. Extra individuals have to read this and understand this facet of the story. I cant believe youre not more fashionable because you positively have the gift.
I like this post, enjoyed this one appreciate it for posting.
Definitely, what a splendid blog and enlightening posts, I surely will bookmark your site.Best Regards!