http://www.ttlsa.com/nginx/nginx-modules-ngx_lua/
nginx lua module is a third-party nginx module developed by Taobao. It can embed the lua language into the nginx configuration, making it extremely convenient to use lua. Enhanced the capabilities of nginx. nginx is famous for its high concurrency, and lua scripts are lightweight. The combination of the two is perfect. Next, please see how to install nginx
+ ngx_lua module. And finally a simple test. If you are an ubuntu system, please see nginx+lua+redis to build high-concurrency applicationsSystem environment: centos/redhatPrepare the following software packages before installation
· nginx address: http://www.nginx.org
· luajit address: http://luajit.org/download.html
· HttpLuaModule address: http://wiki.nginx.org/HttpLuaModule1. Download Install LuaJIT
|
# cd /usr/local/src
# wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
Successfully
built LuaJIT
make[1]:Leaving directory`/usr/ local/src/ LuaJIT 2.0.2= ===
# make installThe following content appears, indicating that the installation is successful====Successfully installed LuaJIT 2.0.2
to
/usr/local==== 2. Download and prepare nginx lua module #
cd /usr/local/src#
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz#
tar -xzvf v0.8.6
3. Install nginx3.1 Install
|
# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.4.2.tar.gz
# tar -xzvf nginx-1.4.2.tar.gz
# cd nginx-1.4.2
//First import the environment variables and tell nginx where to find luajit
# export LUAJIT_LIB= /usr/local/lib
# export LUAJIT_INC=/usr/local/include/luajit-2.0
# ./configure --prefix=/usr/local/nginx-1.4.2 --add- module=../lua-nginx-module-0.8.6
# make -j2
# make install
3.1 Common errors
1
2
3
4
#
/usr/local/nginx-1.4.2/sbin/nginx -v
./objs/nginx:error
whileloading
shared
libraries:libluajit-5.1.so.2:cannot
open
shared
objectfile:No
such
file
ordirectory
Solution:
#
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
4. nginx lua configuration nginx configuration file adds the following configuration:
|
location~*^/2328(/.*) {
default _type'text/plain';
content_by_lua'ngx.say("hello, ttlsa lua")';
}
5. Start the test5.1 Start nginx
1
#
/usr/local/nginx-1.4.2/sbin/nginx
5.2 Access Test
1
2
#
curl http://test.ttlsa.com/2328/
hello,ttlsa
lua//Use curl test
nginx lua test screenshot nginx lua test
nginx ngx_ The installation of Lua ends here
Please indicate the source for reprinting: http://www.ttlsa.com/html/2328.html
The above introduces the nginx + ngx_lua installation test, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.