1、 安裝建議下載openresty ,包比較全,安裝簡單方便;
下載地址 http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
2、編譯安裝
tar xzvf ngx_openresty-1.7.10.1.tar.gzcd ngx_openresty-1.7.10.1./configure --with-luajitmakemake 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教程有興趣的朋友有所協助。