8. / 308
• embeds Lua/LuaJIT into Nginx
• has 100% non-blocking API
• has many libraries provided by OpenResty
• memcached, mysql, redis, etc.
ngx_lua
9. / 309
# load from /etc/nginx/scripts/?.lua and default root
lua_package_path "/etc/nginx/scripts/?.lua;;";
server {
listen 80;
# GET /fact?a=4 -> 24 (4! = 4 * 3 * 2 * 1)
location /fact {
content_by_lua "
local val = 1
for i = 2, ngx.var.arg_a do
val *= i;
end
";
}
# same code in file
location /fact_script {
content_by_lua_file "fact.lua";
}
}
28. / 3028
Logical Delete
local memcached = require "resty.memcached"
local uri = ngx.var.request_uri
local memc = memcached:new()
local val, flags, err = memc:get(request_uri)
if val and val ~= "200" then
exit(tonumber(val))
end
logical_delete.lua
location / {
access_by_lua_file logical_delete.lua;
}