Hello!
2014-07-21 4:41 GMT-07:00 Lei King:
> 是这样的,我需要在lua脚本中实现一个类似proxypass的功能,根据url把本地的一个文件返回。
>
使用 ngx.exec() 直接发起内部跳转到你配置了静态文件服务的 location 就好了。例如:
location /file {
alias /var/www/files;
}
location = /lua {
content_by_lua 'return ngx.exec("/file/me.jpg")'
}
从性能上讲,各种选择的开销基本上是下面的顺序:
1. ngx.exec + nginx 自己的静态文件服务
2. 直接在 Lua 里自己进行文件 IO 并输出给下游。
3. 通过 ngx.location.capture* 发起子请求到 nginx 自己的静态文件服务,再输出给下游。
Regards,
-agentzh