Home  >  Article  >  Backend Development  >  How to use nginx+lua+redis

How to use nginx+lua+redis

WBOY
WBOYOriginal
2016-08-08 09:24:391161browse

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 install
3. 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;
}

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn