WordPress性能优化

自写博客以来,本人一直用WordPress做建站程序。有人肯定会问,都2020年了,为什么还用WordPress,不用Hexo、Jekyll、Github Pages、Medium呢?个人认为主要是WordPress的主题/插件系统太牛逼,从而开发者、用户众多,许多想要的功能,点点鼠标装上插件就实现了,因此生态非常完善,远超其他建站程序。

用了这么久的WordPress,对WordPress的性能优化也有了不少的经验。目前本站峰值PV 3万,峰值IP 1.6万,alexa排名大概15-18万之间,运行在阿里云1核2G 峰值100m带宽的t5突发性能实例上,平均cpu使用率在10%以下,内存占用基本不超过1G,非常平稳:

阿里云监控信息阿里云监控信息

一直用这么低配的机器跑访问量过万的网站,底气来源于本人对WordPress和服务器做了如下优化:

1. 运行最新版的操作系统及软件。最新版的操作系统、软件不仅修复安全bug,还有明显的性能提升。托管本站vps的操作系统是运行5.5内核的CentOS 7(刚买时CentOS 8还未发布,不然肯定上8),启用BBR模块、从remi源安装php 7.4、redis 5最新版、从Nginx、MariaDB官方源安装的最新版Nginx、MariaDB;

2. php启用opcache模块,session存储到redis,nginx和php-fpm通过unix socket通信;

3. Nginx启用gzip压缩,静态资源缓存时间设置为最大;

4. WordPress安装缓存插件,例如W3 Total Cache、 WordPress Super Cache、Autoptimize等,本站用的Autoptimize,可以删除谷歌字体;

5. 移除wp-login.php,xmlrpc.php的直接访问。可以通过Redirection等插件实现,但本人更推荐通过Nginx直接将这两个地址重定向,操作请参考 WordPress防止密码爆破。这个做法不仅安全,避免暴力破解,还能避免无聊/恶意的人消耗CPU;

6. 启用Nginx的缓存,强烈推荐,操作指南: 使用Nginx缓存加速WordPress站点

7. 禁用WordPress自带的cron任务,改成crontab执行。

以上便是个人实施的非常有效的优化手段,其他老生常谈的删除多余主题、插件等,并不认为有多大用处。还有Mysql数据库优化,个人认为比较专业,没有太通用的方案(query cache马上就要被移除了,那些还在说配置query cache的教程是不是不用看了?)。另外个人认为一个很重要的优化手段是使用SSD硬盘,但是本站的机器还是普通硬盘,并未实践。

如果你还有其他有效的性能优化技术,欢迎指点!

参考

1. The Ultimate Speed Guide for WordPress on NGINX

2. 使用Nginx缓存加速WordPress站点

留言评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select * from vps_autoblog_queue where is_running >0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=6 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=6 and source_url_key='85f8e27ce55bd78fd33f47d2b1409198'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(6,'https://www.hijk.pw/post-sitemap.xml','85f8e27ce55bd78fd33f47d2b1409198',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=4 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=4 and source_url_key='54b1dccf98c13c81f546faf82132bc77'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(4,'https://ssr.tools/sitemap-posttype-post.2020.xml','54b1dccf98c13c81f546faf82132bc77',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=2 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=2 and source_url_key='91372ddcd9e4809b115feaa5b6f00815'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(2,'https://tlanyan.me/post-sitemap.xml','91372ddcd9e4809b115feaa5b6f00815',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=7 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=7 and source_url_key='569e17863f7693f1afa9e9256af9dcff'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(7,'https://aisoa.cn/sitemap.xml','569e17863f7693f1afa9e9256af9dcff',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=9 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=9 and source_url_key='cc9416f8df40d8c3a48e66856b1cd6fd'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(9,'https://www.v2rayssr.com/sitemap.xml','cc9416f8df40d8c3a48e66856b1cd6fd',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select count(*) from vps_autoblog_queue where task_id=10 and is_running>0

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,fetched,is_running,last_date_time from vps_autoblog_queue where task_id=10 and source_url_key='74714f67855820f0c701ce905b231f27'

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
insert into vps_autoblog_queue(task_id,source_url,source_url_key,create_date_time,not_check_stoped,post_interval) values(10,'https://doubibackup.com/sitemap.xml','74714f67855820f0c701ce905b231f27',1750369332,0,0)

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,is_running,last_post_time,post_interval,not_check_stoped from vps_autoblog_queue WHERE is_running>0 and fetched=0 order BY id ASC

WordPress数据库错误: [Table 'ssrvps.vps_autoblog_queue' doesn't exist]
select id,sn_id from vps_autoblog_queue WHERE is_running=0 and fetched=0 order BY id ASC LIMIT 1