最近,在一台测试服务器上,安装了多个 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 very cool web site!! Man .. Excellent .. Wonderful .. I'll bookmark your website and take the feeds also? I am glad to seek out a lot of helpful information here in the publish, we need develop extra techniques on this regard, thank you for sharing. . . . . .
Wonderful website you have here but I was curious if you knew of any message boards that cover the same topics talked about in this article? I'd really like to be a part of group where I can get comments from other experienced people that share the same interest. If you have any recommendations, please let me know. Kudos!
I all the time used to read post in news papers but now as I am a user of net thus from now I am using net for articles, thanks to web.
Hi! I've been following your website for a while now and finally got the courage to go ahead and give you a shout out from Atascocita Texas! Just wanted to tell you keep up the good job!
I relish, cause I discovered just what I was taking a look for. You've ended my 4 day long hunt! God Bless you man. Have a nice day. Bye
I am really impressed along with your writing talents as smartly as with the layout in your weblog. Is that this a paid theme or did you customize it yourself? Anyway keep up the nice quality writing, it is rare to peer a nice weblog like this one today!
I'm really inspired with your writing skills and also with the layout on your weblog. Is this a paid subject or did you modify it your self? Anyway stay up the nice quality writing, it is rare to see a nice weblog like this one these days.
Great article, totally what I wanted to find.