您好,欢迎访问一九零五行业门户网

另外一种搭建nginx_lua环境的方法

使用大牛 zhangyichun(http://openresty.org/) 提供的集成包快速安装。
非常简单,下载 ngx_openresty,该集成包中有:nginx,lua或luajit,ngx_lua,以及一些有用的nginx第三方模块。
例如:
nginx的第三方模块redis,这个包实质就是一个.lua文件,是个库文件,提供一些访问redis的接口:
将其下载下来: 
git clone https://github.com/agentzh/lua-resty-redis.git
拷贝:
该包中,有一个 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.redislocal 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) returnendres, err = cache:set(dog, an aniaml)if not ok then ngx.say(failed to set dog: , err) returnendngx.say(set result: , res)local res, err = cache:get(dog)if not res then ngx.say(failed to get dog: , err) returnendif res == ngx.null then ngx.say(dog not found.) returnendngx.say(dog: , res)local ok, err = cache:close()if not ok then ngx.say(failed to close:, err) returnend
在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教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息