: 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.