非常简单,下载 ngx_openresty,该集成包中有:nginx,lua或luajit,ngx_lua,以及一些有用的nginx第三方模块。
例如:
nginx的第三方模块redis,这个包实质就是一个.lua文件,是个库文件,提供一些访问redis的接口:
将其下载下来:
git clone https://github.com/agentzh/lua-resty-redis.git
拷贝:
MATLAB(矩阵实验室)是MATrix LABoratory的缩写,是一款由美国The MathWorks公司出品的商业数学软件。MATLAB是一种用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。除了矩阵运算、绘制函数/数据图像等常用功能外,MATLAB还可以用来创建用户界面及与调用其它语言(包括C,C++和FORTRAN)编写的程序。MATLAB基础知识;命令窗口是用户与MATLAB进行交互作业的主要场所,用户输入的MATLAB交互命令均在命令窗口执行。 感兴趣的朋友可以
该包中,有一个 Lib 目录,将 Lib 目录下的文件和子目录拷贝至上文lua_package_path配置的目录(这里是/data/nginx-1.4.2/)下
再写个简单的lua程序连接redis并获取里面的内容:
例如:写个test_redis.lua放在/data0/nginx-1.4.2/lua/下
local redis = require "resty.redis"
local cache = redis.new()
local ok, err = cache.connect(cache, '127.0.0.1', '6379')
cache:set_timeout(60000)
if not ok then
ngx.say("failed to connect:", err)
return
end
res, err = cache:set("dog", "an aniaml")
if not ok then
ngx.say("failed to set dog: ", err)
return
end
ngx.say("set result: ", res)
local res, err = cache:get("dog")
if not res then
ngx.say("failed to get dog: ", err)
return
end
if res == ngx.null then
ngx.say("dog not found.")
return
end
ngx.say("dog: ", res)
local ok, err = cache:close()
if not ok then
ngx.say("failed to close:", err)
return
end
在nginx.conf里面配置对应的访问位置:
location /test_redis {
content_by_lua_file lua/test_redis.lua;
}
[root@localhost conf]# curl http://localhost/test_redis
set result: OK
dog: an aniaml
以上就介绍了另外一种搭建nginx_lua环境的方法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。









