在 nginx.conf 中配置
- 在 http 节点中配置;
location /staticitem/get {
default_type "text/html";
content_by_lua_file ../lua/staticitem.lua;
}
创建 staticitem.lua 脚本
ngx.say("hello static item lua");
重启 nginx
sudo sbin/nginx -s reload
验证
- 访问 http://localhost/staticitem/get,页面返回 hello static item lua;
content_by_lua 的意义
- 通过针对特定 url 的请求,用 lua 脚本完成业务,避免请求打到后端应用服务器、Redis、MySQL;
更多推荐
Nginx Lua 实战 | content_by_lua 插载点
发布评论