How to Use nginx + lua + redis

Source: Internet
Author: User
: This article describes how to use nginx + lua + redis. if you are interested in the PHP Tutorial, refer to it. 1. we recommend that you download openresty for installation. the package is comprehensive and easy to install;

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 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 ;;";

# Disable lua script cache so that nginx does not need to be restarted for script modification every time the script is loaded.

Lua_code_cache off;

4. nginx lua script usage

Execute scripts in the config file

# 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 );
';
}

External lua script file call

Location/extlua {
Content_by_lua_file/home/lua_script/redis_test.lua;
}
5. curl test the 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"

Double quotation marks are required for url addresses with multiple parameters.

The above describes how to use nginx + lua + redis, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.