nginx+lua+redis 使用方法,nginxredis


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地址要加双引号



相关内容

    暂无相关文章