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.