nginx+lua+redis 使用方法

WBOY
发布: 2016-08-08 09:24:39
原创
1163 人浏览过

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教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!