Lua是一種跟JavaScript很像的語言,Ngix_Lua同樣使用異步單線程,語法甚至比JS更加簡單,之前的評測指出,Ngix_lua的性能幾乎是Node.JS的一倍。
Nginx 特點(diǎn)
1.流行的高性能HTTP服務(wù)器
2.事件驅(qū)動(dòng)(異步)架構(gòu)
3.少量且可測內(nèi)存占用
4.聲明性配置語言
5.基于C的可擴(kuò)展模塊
通過lua-nginx-module即可在nginx上啟動(dòng)lua腳本。
一個(gè)例子:
代碼如下:
location / {
content_by_lua '
local res = ngx.location.capture("/sub")
if res.status >= 500 then
ngx.exit(res.status)
end
ngx.status = res.status
ngx.say(res.body)
';
}
location /sub {
echo "Hello, Sub-Request!";
}
lua-nginx-module在Github上的項(xiàng)目地址 https://github.com/openresty/lua-nginx-module
新聞熱點(diǎn)
疑難解答
圖片精選