萌牛小站 萌牛小站
  • 运维
  • Shell
  • 杂项
  • 系统
    • Windows
    • macos
    • Linux
首页 › Linux › Wordpress nginx 静态web服务器 缓存 cache

Wordpress nginx 静态web服务器 缓存 cache

萌牛
12 月前

Wordpress nginx 静态web服务器 缓存 cache

1.首先wordpress安装nginx helper 插件,帮助你在修改文章添加文章 这些情况下 自动刷新对应页面缓存的作用

2.WEB服务器准备:

首先给nginx添加nginx_cache_purge缓存清除模块

模块项目地址:官方一直没更新的模块版本地址为https://github.com/FRiCKLE/ngx_cache_purge

官方偷偷更新的新版本清除模块,在debian 官方模块里 哈哈,如果使用debian官方自带的nginx,那你可以使用apt来安装 libnginx-mod-http-cache-purge 这个模块

如果你想使用自己编译的nginx并使用这个最新的模块 项目地址为:https://salsa.debian.org/nginx-team/libnginx-mod-http-cache-purge 切换分支为upstream 这个就是最新版本 2.5.3

编译方法为:

nginx -V    ###查看编译参数
在编译参数最后 添加 
--add-module=/xxx/libnginx-mod-http-cache-purge/  ### xxx替换为模块文件夹的绝对位置
编译完成后 直接复制nginx编译文件夹下面的objs/nginx 替换 重启服务就行了

接下来开始设置nginx 的配置:

首先在http块里添加如下参数:

fastcgi_cache_path /var/run/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;

第一行参数里的WORDPRESS可以修改为任意名称,这个是缓存识别的名称

接下来在对应域名server块配置里添加如下参数:

# POST requests and urls with a query string should always go to PHP
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;
}

# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    set $skip_cache 1;
}

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
}
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}

location purge这个里面的WORDPRESS记得修改为你对应的缓存标识

接下来还需要在 location php 这个识别php文件的里面添加如下参数:

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid  60m;

保存配置 重启nginx 缓存已经配置完成 然后开启nginx helper 可以自动清除缓存

0

评论 (0)

取消
    发表评论

猜你喜欢

  • Windows11 24h2 显示器手动校色后正确生效方法
  • photoshop 2025 oniric辉光插件无法使用解决
  • qnap 使用 acme.sh ssl 证书
  • 群辉 synology acme ssl证书配置
  • 解决pandapro2.4.1导致prismatic中的prism.js代码高亮第一行有一个空格

Search

Copyright © 2022-2025 萌牛小站