在之前的一篇文章中我们介绍过, 在高并发情况下,应该使用异步模式
Lua是一种跟JavaScript很像的语言,Ngix_Lua同样使用异步单线程,语法甚至比JS更加简单,之前的评测指出,Ngix_lua的性能几乎是Node.JS的一倍。
Nginx 和 Lua特点,来自 Slides
Nginx nginx.org
- 流行的高性能HTTP服务器
- 事件驱动(异步)架构
- 少量且可测内存占用
- 声明性配置语言
- 基于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

I didn like lua