Nginx + LUA,如何输出文件? [英] Nginx + LUA, how to output file?

查看:70
本文介绍了Nginx + LUA,如何输出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Nginx + Lua 中文件输出有问题.我选择LUA,因为nginx的逻辑相当复杂,基于referrer或子域等.

Having trouble with file output in Nginx + Lua. I chosen LUA, because nginx logic is pretty complicated, based on referrer or subdomains, etc.

有像/img/am1/s/1.jpg 这样的请求,我需要检查/somepath/am1/1.jpg 中是否存在文件.如果存在,则输出它,否则将请求代理到后端.

Having request like /img/am1/s/1.jpg I need to check if file exists in /somepath/am1/1.jpg. If it exists, then output it, otherwise proxy request to backend.

推荐答案

好的,找到了

content_by_lua '
    local file = "/path..."
    local f = io.open(file, "rb")
    local content = f:read("*all")
    f:close()
    ngx.print(content)
';

这篇关于Nginx + LUA,如何输出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆