slowfs: NGINX SlowFS Cache Module
安装
您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:
- RedHat Enterprise Linux 7、8、9 和 10
- CentOS 7、8、9
- AlmaLinux 8、9
- Rocky Linux 8、9
- Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-slowfs
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-slowfs
通过在 /etc/nginx/nginx.conf 的顶部添加以下内容来启用该模块:
load_module modules/ngx_http_slowfs_module.so;
本文档描述了 nginx-module-slowfs v1.11,于 2020 年 8 月 23 日发布。
ngx_slowfs_cache 是一个 nginx 模块,允许缓存静态文件(使用 root 指令提供)。这使得可以为存储在慢文件系统上的文件创建快速缓存,例如:
- 存储:网络磁盘,缓存:本地磁盘,
- 存储:7.2K SATA 驱动器,缓存:RAID0 中的 15K SAS 驱动器。
警告!当缓存放置在与源相同速度的磁盘上时,使用此模块没有意义。
赞助商
ngx_slowfs_cache 完全由 c2hosting.com 资助。
配置说明
slowfs_cache_path 和 slowfs_temp_path 的值应指向同一文件系统,否则文件将被复制两次。
当前 ngx_slowfs_cache 在启用 AIO 时无法工作。
配置指令
slowfs_cache
- 语法:
slowfs_cache zone_name - 默认:
none - 上下文:
http,server,location
设置用于缓存的区域(之前使用 slowfs_cache_path 定义)。
slowfs_cache_key
- 语法:
slowfs_cache_key key - 默认:
none - 上下文:
http,server,location
设置缓存的键。
slowfs_cache_purge
- 语法:
slowfs_cache_purge zone_name key - 默认:
none - 上下文:
location
设置用于从缓存中清除选定页面的区域和键。
slowfs_cache_path
- 语法:
slowfs_cache_path path [levels] keys_zone=zone_name:zone_size [inactive] [max_size] - 默认:
none - 上下文:
http
设置缓存区域及其结构。
slowfs_temp_path
- 语法:
slowfs_temp_path path [level1] [level2] [level3] - 默认:
/tmp 1 2 - 上下文:
http
设置临时区域,在文件移动到缓存区域之前存储文件。
slowfs_cache_min_uses
- 语法:
slowfs_cache_min_uses number - 默认:
1 - 上下文:
http,server,location
设置文件被复制到缓存之前的使用次数。
slowfs_cache_valid
- 语法:
slowfs_cache_valid [reply_code] time - 默认:
none - 上下文:
http,server,location
设置文件将从缓存中提供的时间。
slowfs_big_file_size
- 语法:
slowfs_big_file_size size - 默认:
128k - 上下文:
http,server,location
设置“大”文件的最小文件大小。工作进程在开始复制“大”文件之前会 fork() 子进程,以避免任何服务中断。
配置变量
$slowfs_cache_status
表示缓存文件的可用性。
可能的值为:MISS、HIT 和 EXPIRED。
示例配置
http {
slowfs_cache_path /tmp/cache levels=1:2 keys_zone=fastcache:10m;
slowfs_temp_path /tmp/temp 1 2;
server {
location / {
root /var/www;
slowfs_cache fastcache;
slowfs_cache_key $uri;
slowfs_cache_valid 1d;
}
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
slowfs_cache_purge fastcache $1;
}
}
}
测试
ngx_slowfs_cache 附带了基于 Test::Nginx 的完整测试套件。
您可以通过运行以下命令进行测试:
$ prove
另请参阅
GitHub
您可以在 nginx-module-slowfs 的 GitHub 仓库 中找到此模块的其他配置提示和文档。