Nginx+lua+redis High Concurrent Application construction

Source: Internet
Author: User
Tags install redis

Ngx_lua Lua into Nginx, let Nginx run Lua script. High concurrency, non-clogging process for various requests.

The URL requires Nginxserver, and LUA queries Redis to return the JSON data.


I. Installation Lua-nginx-module

See the architecture of LNMLGC


Two. Installing the Redis2-nginx-module module

Get Https://github.com/openresty/echo-nginx-module
Get Https://github.com/openresty/redis2-nginx-module
Get Https://github.com/agentzh/set-misc-nginx-module.git

#
./configure--prefix=/usr/local/nginx   \
--with-debug                            \
--with-http_stub_status_module   &NB Sp      \
--with-http_ssl_module                  \
--with -pcre=. /pcre-8.21                \
--add-module=. /ngx_devel_kit-0.2.19    \
--add-module=.. /lua-nginx-module-0.9.8  \
--add-module=. /echo-nginx-module       \
--add-module=. /redis2-nginx-module     \
--add-module=. /set-misc-nginx-module

# make
# make install

Three. Install Lua-redis-parser
# git clone https:
//github.com/agentzh/lua-redis-parser.git
# Export Lua_ include_dir=/usr/local/include/luajit-2.0
# make CC=GCC
# make install CC=GCC

four. Installing the JSON
# wget http:
//files.luaforge.net/releases/json/json/0.9.50/json4lua-0.9.50.zip
# Unzip Json4lua-0.9.50.zip
# cp json4lua-0.9.50/json/json.lua/usr/local/lua/lib/

Five. Install Redis-lua
# git clone https:
//github.com/nrk/redis-lua.git
# CP redis-lua/src/redis.lua/usr/ local/lua/lib/

six. Configure
..... http {    ...    Upstream Redis_pool {        server localhost:6379;        KeepAlive;        Defines the connection pool size when the number of connections reaches this number. Maybe the connection is short connection    }    server {        ...        location/get_redis{            #internal;            Set_unescape_uri $key $arg _key;            Redis2_query Hgetall $key;            Redis2_pass redis_pool;        }        Location/json {            content_by_lua_file Conf/test.lua;}}    }

# VI Test.lua, placed under the Nginx.conf folder
Local JSON = require ("JSON") local parser = require ("Redis.parser") Local res = Ngx.location.capture ("/get_redis", {  args = {key = Ngx.var.arg_key}}) If Res.status = = then  reply = parser.parse_reply (res.body)  value = Json.enco De (Reply)  Ngx.say (value)  a = Json.decode (value)  Ngx.say (a[2]) end

Seven. Test
# REDIS-CLI
127.0.0.1:6379> hmset Ttlsa www www.ttlsa.com mail mail.ttlsa.com
Ok
127.0.0.1:6379> Hgetall Ttlsa
1) "www"
2) "Www.ttlsa.com"
3) "Mail"
4) "Mail.ttlsa.com"

# Curl Http://localhost/json?

Key=ttlsa

["www", "www.ttlsa.com", "Mail", "mail.ttlsa.com"]

Www.ttlsa.com

Nginx+lua+redis High Concurrent Application construction

Related Article

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.