WordPress 手动优化

1、禁用文章修订版,在 wp-config.php文件中添加:

  define('WP_POST_REVISIONS', false);

再用WP clean up插件清理下sql
2、禁用自动保存,修改下面连个,注释掉,测试版本4.7.1

 wp-admin/post-new.php 直接注释掉
wp-admin/post.php 注释掉 在if ( 'attachment' !== $post_type );《---加个分号
如://wp_enqueue_script('autosave');

插件安装
(我的VPS配置的是nginx/1.10.2+PHP 7.1.0+memcached 1.4.34 开启fastcgi_cache):
查Nginx是否安装ngx_cache_purge

 nginx -V 2>&1 | grep -o ngx_cache_purge

为了方便我建议到:http://caohuan.com/1-service-in.html 下个安装包,也推荐用oneinstack

 cd /root/oneinstack/src
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar xzf ngx_cache_purge-2.3.tar.gz
tar xzf nginx-1.10.2.tar.gz
cd nginx-1.10.2
nginx -V #查看nginx编译参数,最后加上--add-module=../ngx_cache_purge-2.3
./configure --prefix=/usr/local/nginx --user=www --group=www \
--with-http_stub_status_module --with-http_v2_module --with-http_ssl_module \
--with-ipv6 --with-http_gzip_static_module --with-http_realip_module \
--with-http_flv_module --with-ld-opt=-ljemalloc \
--add-module=../ngx_cache_purge-2.3
make  #编译
mv /usr/local/nginx/sbin/nginx{,_`date +%F`}  #备份nginx
cp objs/nginx /usr/local/nginx/sbin
nginx -V 2>&1 | grep -o ngx_cache_purge
# 显示ngx_cache_purge表示已经安装成功

使nginx配置生效

 service nginx reload

重启系统后shm内存中nginx-cache文件夹会丢失,为了使重启生效(自动创建文件夹),修改/etc/init.d/nginx的make_dirs下一行(大概52行)添加:

 [ ! -d '/dev/shm/nginx-cache' ] && { mkdir /dev/shm/nginx-cache; chown -R ${user}.$user /dev/shm/nginx-cache; }

3. WordPress安装Nginx Helper插件或 NGINX Cache Optimizer插件
修改wordpress网站根目录wp-config.php添加如下行(dev/shm是centos内存):

 define('RT_WP_NGINX_HELPER_CACHE_PATH','/dev/shm/nginx-cache');

可参考原文:https://blog.linuxeye.com/439.html
然后我们建立一个PHP时间文件,代码:

< ? php echo time(); ? >

测试,缓存了显示的结果不变:

[[email protected] ~]# curl http://caohuan.com/time.php;echo
1488160160
[[email protected] ~]# curl http://caohuan.com/time.php;echo
1488160160
[[email protected] ~]# curl http://caohuan.com/time.php;echo
1488160160
[[email protected] ~]# curl http://caohuan.com/time.php;echo
1488160160
[[email protected] ~]# curl http://caohuan.com/time.php;echo
1488160160
[[email protected] ~]#  curl -X GET -I http://caohuan.com
HTTP/1.1 200 OK
Server: nginx
......
X-Cache: MISS From caohuan.com
X-FastCGI-Cache: MISS

[[email protected] ~]#  curl -X GET -I http://caohuan.com
HTTP/1.1 200 OK
Server: nginx
......
X-Cache: HIT From caohuan.com
X-FastCGI-Cache: HIT

[ro[email protected] ~]#  curl -X GET -I http://caohuan.com
HTTP/1.1 200 OK
Server: nginx
......
X-Cache: HIT From caohuan.com
X-FastCGI-Cache: HIT
 关键的参数在这里:--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2j --with-pcre=../pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=../ngx_cache_purge-2.3

1、我在php7,我打开debug安装WP Super Cache是有错误的,换了wp fastest cache
2、开启nginx的fastcgi_cache,有memcached我这小站也够用的,VPS有不是wordpress所以有是连个一起分着用下。安装插件NGINX Cache Optimizer(这个插件会在wp-content加入object-cache.php但如果你的memcached不工作了这个文件要删除不然网站500),或者可以装一个nginx helper,这个没前者的功能多,两个都可以管理fastcgi_cache缓存,但前者多了个memcached。

vhost配置:
在附件,提供本站正在用的vhost.conf 和nginx.conf,和几篇实用的配置文章,地址不提供了,网站有时站长不做了,技术就流失了,保存下来长久点。

2017-02-19新增nginx无错gzip

 gzip_types text/xsl text/xsd text/x-json text/x-js text/richtext image/webp image/tiff image/bmp font/ttf font/otf font/opentype font/eot audio/wav audio/ogg application/x-web-app-manifest+json application/x-shockwave-flash application/x-msdownload application/xml application/xhtml+xml application/x-font-otf application/vnd.oasis.opendocument.text application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.ms-write application/vnd.ms-project application/vnd.ms-powerpoint application/vnd.ms-opentype application/vnd.ms-excel application/vnd.ms-access application/rss+xml application/pdf application/msword application/java application/font-woff2 application/font-woff application/atom+xml;

下载信息

——-[仅限 VIP 用户下载]——-

成为VIP



去打赏

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏

正在跳转到PayPal…

点赞