Typecho缓存配置,留个备份。
使用条件:
清理缓存插件:gzare/Typecho-NginxHelper
Nginx第三方模块:nginx-modules/ngx_cache_purge
已知问题:
- 阅读量可能无法正常工作
nginx.conf:
#Cache
fastcgi_cache_path /cache/all levels=1:2 keys_zone=TYPECHO:250m inactive=1d max_size=1G;
fastcgi_temp_path /cache/temp;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
#忽略一切nocache申明,避免不缓存伪静态等
fastcgi_ignore_headers Cache-Control Expires;
vhost.conf:
set $skip_cache 0;
#post访问不缓存
if ($request_method = POST) {
set $skip_cache 1;
}
#动态查询不缓存
if ($query_string != "") {
set $skip_cache 1;
}
#pjax查询缓存
if ($query_string ~ "_pjax=(.*)") {
set $skip_cache 0;
}
#后台等特定页面不缓存(其他需求请自行添加即可)
if ($request_uri ~* "/admin/|/action/|/search/|/feed/|baidu_sitemap.xml|sitemap.xml") {
set $skip_cache 1;
}
#对登录的用户不展示缓存
if ($http_cookie ~* "typecho_authCode") {
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;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
# Cache
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-Cache "$upstream_cache_status From $host";
add_header Cache-Control max-age=0;
add_header Nginx-Cache "$upstream_cache_status";
add_header Last-Modified $date_gmt;
add_header X-Frame-Options SAMEORIGIN; # 只允许本站用 frame 来嵌套
add_header X-Content-Type-Options nosniff; # 禁止嗅探文件类型
add_header X-XSS-Protection "1; mode=block"; # XSS 保护
etag on;
fastcgi_cache TYPECHO;
fastcgi_cache_valid 200 301 302 1d;
}