高并发网站架构的外围准则其实就一句话“把一切的用户拜访申请都尽量往前推“,即:能缓存在用户电脑本地的,就不要让他去拜访CDN。 能缓存CDN效劳器上的,就不要让CDN去拜访源(动态效劳器)了。能拜访动态效劳器的,就不要去拜访静态效劳器。以此类推:能不拜访数据库和存储就肯定不要去拜访数据库和存储。 
WordPress最好的优化形式就是尽量不装置插件,Wordpress是典型的PHP-MySQL使用,去做数据库缓存,倒不如让轻量级的Nginx间接去缓存WordPress内容。 
Nginx内置FastCgi缓存,然而不支持主动肃清缓存。当你在Wordpress外面新建/修正一篇文章,或许访客提交评论的时分,主动清空相干的缓存是必要的!Nginx需求装置ngx_cache_purg+量身定做的WordPress缓存清算插件:Nginx Helper。 
1. 装置Nginx ngx_cache_purge模块 
1)查看ngx_cache_purge能否装置 
nginx -V 2>&1 | grep -o ngx_cache_purge 
显示ngx_cache_purge示意曾经装置 
2)装置ngx_cache_purge模块 
《OneinStack》和《lnmp一键装置包》下装置ngx_cache_purge模块 
cd /root/oneinstack/src
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
wget http://nginx.org/download/nginx-1.9.10.tar.gz
tar xzf ngx_cache_purge-2.3.tar.gz
tar xzf nginx-1.9.10.tar.gz
cd nginx-1.9.10
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虚构主机配置文件/usr/local/nginx/conf/vhost/blog.linuxeye.com.conf:
fastcgi_cache_path /dev/shm/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
server {
listen 443 ssl http2;
ssl_certificate /usr/local/nginx/conf/vhost/linuxeye_blog.crt;
ssl_certificate_key /usr/local/nginx/conf/vhost/linuxeye_blog.key;
ssl_ciphers "CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#ssl_stapling on;
#ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
server_name blog.linuxeye.com;
access_log /home/wwwlogs/blog_nginx.log combined;
index index.html index.htm index.php;
include wordpress.conf;
root /home/wwwroot/blog;
set $skip_cache 0;
if ($request_method = POST) {
    set $skip_cache 1;
    }
if ($query_string != "") {
    set $skip_cache 1;
    }
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    set $skip_cache 1;
    }
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
    }
location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid  60m;
    }
location ~ /purge(/.*) {
    allow 127.0.0.1;
    deny all;
    fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
    }
}
 service nginx reload
重启零碎后shm内存中nginx-cache文件夹会失落,为了使重启失效(主动创立文件夹),修正/etc/init.d/nginx的make_dirs下一行增加:
 [ ! -d '/dev/shm/nginx-cache' ] && { mkdir /dev/shm/nginx-cache; chown -R ${user}.$user /dev/shm/nginx-cache; }
3. WordPress装置Nginx Helper插件
WordPress后盾【插件】—【装置插件】搜寻【Nginx Helper】装置即可。如下设置:
修正wordpress网站根目录wp-config.php增加如上行: 
define('RT_WP_NGINX_HELPER_CACHE_PATH','/dev/shm/nginx-cache'); 
以上就是安达网络工作室关于《WordPress速度优化-Nginx fastcgi_cache缓存加速》的一些看法。更多内容请查看本栏目更多内容!
作为一款遭到大少数站长欢送的内容治理零碎,WordPress不只有着弱小的治理性能,而且应用不便,即便是老手也...
民间引见: 1,经过插件能够创立adsense广告位。 2,能够间接经过工具在网管中心验证网站。 之前站长David...
1. 自定义主题图片大小 图片是WordPress主题的重要组成局部,但开发者们有时会忘了对主题图片进行优化。主题...
这篇文章重点引见10个重要的WordPress平安插件和技巧,用来维护WordPress网站或许博客。1. WP Security人工...
本文实例总结了wordpress随机调用显示文章的办法。分享给大家供大家参考。详细办法如下: 在wordpress中要随...
apply_filters()(创立过滤器) apply_filters() 函数用来创立一个过滤器,大少数被用在函数中,是 WordPre...