- 如果是需要对下载文件做一些鉴权处理, 可在nginx.conf 里设置,类似:
location ~ ^/images/(.+)\.png {
default_type application/octet-stream;
access_by_lua_block {
require("some_mod").auth_download_file(ngx.var[1])
}
alias images_dir/$1.png;
}
local file_data = read_file(file_path)
local file_size = string.len(file_data)
ngx.header('Content-Type', 'application/octet-stream')
ngx.header('Content-Disposition', 'attachment;filename=' .. file_name)
ngx.header('Accept-ranges', 'bytes')
ngx.header('Accept-length', file_size)
ngx.print(file_data)