nginx+lua+redis 使用方法

來源:互聯網
上載者:User
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教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.