昨天大鸟分享了Nginx+Redis Cache缓存提速网站,因为Nginx-helper插件是可以开启两个缓存:nginx Fastcgi cache和Redis cache。这两个缓存无论是配置哪个,对于提升网站速度都是非常优秀的。
对于并发来说Redis cache缓存更优秀,不过对于个人博客来说,就是安装一个WP Super Cache也是足够应付日常了,我们应该把更多的心思放在内容上。
今天这篇文章说什么呢,还是关于Nginx+Redis Cache缓存配置,因为昨天说的也比较详细了,所以今天大鸟只是贴一下代码,昨天的代码和今天的代码不太一样,但是功能是一样的。不过学习这篇文章之前,我们需要看看以下文章:
[mark_e]
[/mark_e]
我们打开宝塔面板的网站配置,或者在路径[code]/www/server/panel/vhost/nginx[/code]中把自己网站的conf文件打开配置。把以下代码贴进去,额,该修改的还是要修改下的。
server
{
listen 80;
listen 443 ssl http2;
server_name www.daniao.org;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/www.daniao.org;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
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 /redis-fetch {
internal ;
set $redis_key $args;
redis_pass 127.0.0.1:6379;
}
location /redis-store {
internal ;
set_unescape_uri $key $arg_key ;
redis2_query set $key $echo_request_body;
redis2_query expire $key 14400;
redis2_pass 127.0.0.1:6379;
}
location ~ \.php$ {
set $key "nginx-cache:$scheme$request_method$host$request_uri";
try_files $uri =404;
srcache_fetch_skip $skip_cache;
srcache_store_skip $skip_cache;
srcache_response_cache_control off;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis-fetch $key;
srcache_store PUT /redis-store key=$escaped_key;
more_set_headers 'X-Cache $srcache_fetch_status';
fastcgi_pass unix:/tmp/php-cgi-72.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#以下省略....................
这个配置代码和昨天的代码可以结合起来看,不过任何一个代码都可以成功开启Nginx+Redis Cache缓存。
开启之后,对于网站速度提升有非常大的飞跃^ _ ^


















