Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx + LUA, how to output file?

Tags:

nginx

lua

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

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.

like image 213
Eugene Avatar asked Dec 09 '22 07:12

Eugene


1 Answers

Ok, found it

content_by_lua '
    local file = "/path..."
    local f = io.open(file, "rb")
    local content = f:read("*all")
    f:close()
    ngx.print(content)
';
like image 193
Eugene Avatar answered Dec 11 '22 08:12

Eugene