一,开发环境配置
官方参考文档:https://github.com/openresty/lua-nginx-module#readme
#修改nginx.conf配置
vim /usr/local/nginx/conf/nginx.conf
#lua模块路径,多个之间用”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/local/nginx下找
lua_package_path "/usr/local/lualib/?.lua;;"; #lua 模块
lua_package_cpath "/usr/local/lualib/?.so;;"; #c模块
#为方便开发,我们在/usr/local/nginx/conf/下创建 lua.conf 配置
server {
listen 802;
server_name luaTest;
}
#在nginx.conf中的http部分添加include lua.conf包含此配置
include lua.conf;
#测试是否配置成功
/usr/local/nginx/sbin/nginx -t
如下图则配置成功:
二,HelloWorld程序
#在lua.conf中server部分添加如下配置
location /lua {
default_type 'text/html';
content_by_lua 'ngx.say("hello world")';
}
#重启nginx
/usr/local/nginx/sbin/nginx -s reload
#测试HelloWorld程序
在浏览器输入 http://120.25.233.113:802/lua
三, 程序运行结果