久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

WordPress速度優(yōu)化-Nginx fastcgi_cache緩存加速

Nginx內(nèi)置FastCgi緩存,但是不支持自動(dòng)清除緩存。當(dāng)你在Wordpress里面新建/修改一篇文章,或者訪客提交評(píng)論的時(shí)候,自動(dòng)清空相關(guān)的緩存是必要的!Nginx需要安裝ngx_cache_purg+量身定做的W

高并發(fā)網(wǎng)站架構(gòu)的核心原則其實(shí)就一句話“把所有的用戶訪問請(qǐng)求都盡量往前推“,即:能緩存在用戶電腦本地的,就不要讓他去訪問CDN。 能緩存CDN服務(wù)器上的,就不要讓CDN去訪問源(靜態(tài)服務(wù)器)了。能訪問靜態(tài)服務(wù)器的,就不要去訪問動(dòng)態(tài)服務(wù)器。以此類推:能不訪問數(shù)據(jù)庫和存儲(chǔ)就一定不要去訪問數(shù)據(jù)庫和存儲(chǔ)。

WordPress最好的優(yōu)化方式就是盡量不安裝插件,Wordpress是典型的PHP-MySQL應(yīng)用,去做數(shù)據(jù)庫緩存,倒不如讓輕量級(jí)的Nginx直接去緩存WordPress內(nèi)容。

Nginx內(nèi)置FastCgi緩存,但是不支持自動(dòng)清除緩存。當(dāng)你在Wordpress里面新建/修改一篇文章,或者訪客提交評(píng)論的時(shí)候,自動(dòng)清空相關(guān)的緩存是必要的!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表示已經(jīng)安裝

2)安裝ngx_cache_purge模塊

《OneinStack》和《lnmp一鍵安裝包》下安裝ngx_cache_purge模塊


復(fù)制代碼
代碼如下:

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編譯參數(shù),最后加上--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表示已經(jīng)安裝成功


2. Nginx配置
建議將fastcgi_cache_path設(shè)置tmpfs內(nèi)存中,操作系統(tǒng)不同tmpfs路徑也不同,如下:
 
 CentOS:/dev/shm
Ubuntu和Debian:/run/shm

修改nginx虛擬主機(jī)配置文件/usr/local/nginx/conf/vhost/blog.linuxeye.com.conf:


復(fù)制代碼
代碼如下:

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;
}
}


使nginx配置生效
 

復(fù)制代碼
代碼如下:

service nginx reload

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

今天有個(gè)朋友詢問tp5支持pathinfo的nginx配置怎么寫的問題,所以想著自己總結(jié)分享下,下面這篇文章主要給大家介紹了關(guān)于在Nginx下ThinkPHP5的配置方法,需要的朋友可以參考借鑒,下面話
這篇文章主要給大家介紹了關(guān)于php + nginx項(xiàng)目中權(quán)限的相關(guān)資料,文章介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
主站蜘蛛池模板: 精品国产一区三区 | 国产乱码精品一区二区三区中文 | 国产精品视频一区二区三区 | 特级a欧美做爰片毛片 | 久久久久久国产精品免费免费狐狸 | 日韩中文字幕在线视频 | 中文日韩字幕 | 午夜久久久久久久久久一区二区 | 精品一区二区三区在线观看 | 国产美女一区二区三区 | 免费毛片网站 | 久久激情视频 | 亚洲欧美日韩精品久久亚洲区 | 久久综合亚洲 | 欧美电影一区 | 热99在线 | 亚洲精品乱码久久久久久蜜桃91 | 中文字字幕一区二区三区四区五区 | 亚洲网站在线观看 | 欧美一级特黄aaa大片在线观看 | 国产精品视频在线播放 | 91高清视频在线观看 | 久久国产精品偷 | 看毛片的网站 | 亚洲网一区 | 国产精品久久久久aaaa九色 | 精品国产一级 | 欧美视频区 | 国产在线看片 | 久久久精品一区二区 | 国产精品区二区三区日本 | 亚洲高清一区二区三区 | 九九亚洲| 91一区二区三区 | 亚洲国产一区二区视频 | 每日更新av | 国产精品亚洲成在人线 | 天天干天天操天天看 | 国产一区不卡 | 亚洲一区导航 | 国产一区久久 |