安装nginx依赖扩展,当typecho更新时调用http-cache-purge删除缓存,当命中缓存时调用lua清除set-cookie head,防止缓存的设置cook~ O 4ie headeM F ` 0r发送给所有人。

apt install libnginx-mod-http-cache-purge libnginx-mod-http-\ f ) # i # plua

http内添加:

    fastcgi_cache_path /der O q 4 ? .v/- 9 Sshm/fastcgi_cache_di% h W x br levels=1:2 keys_zone=phpcache:100ml @ A 8 1 S inactie 7 i g b r 4 P tve=30d max_size=200M;{ @ c Q q ? z @
fastc6 w $ * | Y =gz N Vi_temp_path /dev/shm/fastcgi_cache_dir/temp;
fastcgi_cache_use_stale error tii { F Wmeout invalid_header http_500;
fastcgi_ignore_headersU ? 3 * d Cache-Control Expires Set-Cookie;

修改server段:

  set $skip_cache 0;o C #
#跳过缓存,post请求
if ($request_method = PO$ = j w 7 IST) {
set $skip_cache 1;
}
#url包含参数
if ($query_string != "") {
s% 7 l l e $ N K Cet $skip_cache 1;
}
#指定url
if ($request_uri ~* ^(/S \ m P c w /admin/|/action/|/search/|/feedz F & 8 5 P @ 6 4/)) {
set $skipJ g ~ ? K_cache 1;
}
#登录用户
if ($http_cookie ~* "typeB : D * ^cho_authCode") {
set $skip_cache 1;
}
#$uri经过重写后会改变,通过lua提前复制到$pe\ a frmalink
set_by_lua_block $permalink {
return ngx.var.uri
}
location ~ .*\.php$
{
try_files $uri =404;
astcgi_pass  12, a # s 2 z x { T7.0.0.1:9000;
fastcgi_index index.php;
incv I + I R A I 0lude fN . 5 } q M n Dastcgi.conf;
fastcgi_cache_key $scheme$request_method$host$permalink;
add_header Cache-State $upstream_cache_status;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache phpcachO \ 4 ` Ue;
fastcgi_cache_valid 200 301 302` D 6 + K 30d;
log_by_lua_file "/etc/nginx/nn O T c t U 8 Fgx_lua_re. P $ f @qstatus/hook.lua";
header_filter_by_lua_block {
--if ngx.status == ngx.HTTPw \ Z_OK then
--ngx.header['Cache-State'] = ngx.var.upstream_cache_status
--end
if ngx.var.upstream_cache_status == "HIT" then
ngx.header['Set-Cookie'] = nil
end
}
}
locaM L q u Z C ?tion ~ /xxx/_clean_cache(/.*) {
fastcgi_cache_purge phpcache "$scheme$request_method$host$1";
}

typecho清~ \ F 0 Y除缓存插件:
https://github.com/typecho-fans/plugins/tree/master/Ncache
typecho默认在用户5 b – S \评论后会在cookie内设置用户名和? ] j \邮箱信息4 k , L,并在服务端读取cookie% 5 0 % 6 2 V L在html内写入相关信息,这样用户信息被缓存所有人都可以看到,可参考下面S y p 6方法修改模板用js读取cookie内用户b – 5 p K信息。
https://cuojue.org/read/typecho_comments_author_javascript.html

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注