回答
收藏
分享
举报
当查看到本地文件不存在时,NGINX plus中是否能执行shell命令?
提问于2021-08-12 10:31

浏览 674

文章标签

当查看到本地文件不存在时,NGINX plus中是否能执行shell命令?我们想当出现不存在的文件时,执行脚本主动同步,我们是有另外的job在定时同步的,不过仍然是会有时间差,就是在这个时间中访问不存在的文件时,执行主动同步,然后返回用户,而不是返回404

已修改于2023-03-17 02:24



写下您的回答
发表回答
全部回答(1)

按点赞数排序

按时间排序

不应该这么来弄,应该是结合lua/njs来做,通过njs/lua来判断文件是否存在

error_log stderr notice;
daemon off;
events { }

http {
include /usr/local/openresty/nginx/conf/mime.types;

server {
listen 80;

location @image_server {
content_by_lua_file "file_judge.lua";
}

location ~ ^/images/(?<sig>[^/]+)/(?<size>[^/]+)/(?<path>.*\.(?<ext>[a-z_]*))$ {
root cache;
set_md5 $digest "$size/$path";
try_files /$digest.$ext @image_server;
}
}

}

-- make sure the file exists
local file = io.open(source_fname)

if not file then
return_not_found()
end

file:close()

lua里面去判断文件存不存在

赞同

0

回复举报

回答于2021-08-13 10:32



回复罗剑锋
回复
提问者
NGINX官方账号
这家伙很懒还未留下介绍~
242
文章
21
问答
198
粉丝
相关问答