Lua是一種跟JavaScript很像的語言,Ngix_Lua同樣使用異步單線程,語法甚至比JS更加簡單,之前的評測指出,Ngix_lua的性能幾乎是Node.JS的一倍。
Nginx 特點
1.流行的高性能HTTP服務器
2.事件驅動(異步)架構
3.少量且可測內存占用
4.聲明性配置語言
5.基于C的可擴展模塊
通過lua-nginx-module即可在nginx上啟動lua腳本。
一個例子:
代碼如下:
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上的項目地址 https://github.com/openresty/lua-nginx-module
新聞熱點
疑難解答