Home >Backend Development >PHP Tutorial >How to use nginx+lua+redis
1. For installation, it is recommended to download openresty. The package is relatively complete and the installation is 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.gz cd ngx_openresty-1.7.10.1 ./configure --with-luajit make make install3. Modify nginx config - /usr/local/openresty/nginx/conf/nginx.conf
# Add the following to the http section to introduce redis support:
lua_package_path "/home/ngx_openresty-1.7.10.1/bundle/lua-resty-redis-0.20/lib/resty/?.lua;;";
#Close The lua script cache makes it possible to load the script every time and modify the script without restarting nginx
lua_code_cache off;
4. How to use nginx lua script
Execute the script 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";
'; lua script file call
location /extlua{
content_by_lua_file /home/lua_script/redis_test.lua;
}
post request: curl -d "id=1&age=20" "http://127.0.0.1/extlua"
Multiple parameter url addresses must be enclosed in double quotes
The above introduces how to use nginx+lua+redis, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.