当前位置:首页 > 服务器技术 > nginx

nginx+lua+redis使用方法

1、 安装建议下载openresty ,包比较全,安装简单方便;

下载地址 http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz

2、编译安装

tar xzvf ngx_openresty-1.7.10.1.tar.gz
cd ngx_openresty-1.7.10.1
./configure --with-luajit
make
make install
3、修改nginx config - /usr/local/openresty/nginx/conf/nginx.conf

# http段内添加下面引入redis支持:

lua_package_path "/home/ngx_openresty-1.7.10.1/bundle/lua-resty-redis-0.20/lib/resty/?.lua;;";

#关闭lua脚本缓存,使得每次调用加载脚本,脚本修改不需要重启nginx

lua_code_cache off;

4. nginx lua脚本使用方法

config文件内执行脚本

#lua script excute in this config
location /lua{
set $test "hello world.";
content_by_lua '
ngx.header.content_type = "text/plain";
ngx.say(ngx.var.test);
';
}

外部lua脚本文件调用

location /extlua{
content_by_lua_file /home/lua_script/redis_test.lua;
}
5、curl测试get post请求方法

get请求: curl "http:/127.0.0.1/lua?id=1&name=pop"

post 请求: curl -d "id=1&age=20" "http://127.0.0.1/extlua"

多个参数url地址要加双引号

以上就介绍了nginx+lua+redis 使用方法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!