Nginx+lua+redis How to use

Source: Internet
Author: User
Tags lua php tutorial
1, installation recommendations Download Openresty, package comparison, installation simple and convenient;

Download Address http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz

2. Compile and install

Tar xzvf ngx_openresty-1.7.10.1.tar.gzcd ngx_openresty-1.7.10.1./configure--with-luajitmakemake Install
3. Modify Nginx config-/usr/local/openresty/nginx/conf/nginx.conf

# Add the following to the introduction of Redis support in the HTTP segment:

Lua_package_path "/home/ngx_openresty-1.7.10.1/bundle/lua-resty-redis-0.20/lib/resty/?" LUA;; ";

#关闭lua脚本缓存, so that every time the load script is called, the script modification does not need to restart Nginx

Lua_code_cache off;

4. How to use the Nginx Lua script

Config file to execute script inside

#lua script Excute in the This config
location/lua{
Set $test "Hello World.";
Content_by_lua '
Ngx.header.content_type = "Text/plain";
Ngx.say (ngx.var.test);
';
}

External Lua script file calls

location/extlua{
Content_by_lua_file/home/lua_script/redis_test.lua;
}
5. Curl Test Get POST request method

GET Request: Curl "Http:/127.0.0.1/lua?id=1&name=pop"

Post request: curl-d "id=1&age=20" "Http://127.0.0.1/extlua"

Multiple parameter URL addresses to double quotation marks

The above describes the use of Nginx+lua+redis, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.