加速WordPress访问速度

首先呢,因为Google在国内不能访问,而Wordpress又默认使用了很多Google上的字体,于是造成了访问异常缓慢,长的时候甚至可能有1分多钟。

为了加快博客访问速度,从多角度下手,用了如下方法

Solution 1

先把Google的字体源改为国内的镜像源,这里偷个懒,就直接用360的镜像了,另外一个原因是使用这个镜像的话,修改起来非常方便。

在Wordpress目录下,有两个文件夹需要改

  • /wp-includes/
  • /wp-content/themes/THE THEMES TAHT YOU ARE USING/

进入这两个目录后,直接执行

sed -i 's/googleapis/useso/' *.php

便修改完成

Solution 2

使用CDN(内容分发网络),这里我是用的七牛的服务 + WP Super Cache插件

在七牛注册、申请空间后,就可以一键加速,记住七牛提供的域名,待会要在WP Super Cache插件中用到。

安装好插件后,进入插件设置,选择CDN,勾选“开启CDN支持”,然后在下方的URL那里填上刚才七牛提供的域名,最后保存设置。

Solution 3

还可以通过Apache的mod headers来设置max-age,以及Apache的mod expires来设置有效期。

/etc/apache2/httpd.conf的末尾添加如下内容

<IfModule mod_headers.c>
        header set Cache-Control "max-age=3600"
</IfModule>
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/gif A2592000
        ExpiresByType image/jpeg A2592000
        ExpiresByType image/png A2592000
        ExpiresByType image/x-icon A2592000
        ExpiresByType application/x-javascript A604800
        ExpiresByType text/css A604800
</IfModule>

当然,具体的时间可以由自己决定。

最后记得重启Apache

service apache2 reload
service apache2 restart

Leave a Reply

Your email address will not be published. Required fields are marked *

one × 1 =