nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以高并发而知名,lua脚本轻便,两者的搭配堪称完美.接下来请看如何安装nginx + ngx_lua模块.以及最后来个简单的测试.
如果你是ubuntu系统,请看nginx+lua+redis构建高并发应用
系统环境:centos/redhat
安装前准备好如下软件包
· nginx 地址:http://www.nginx.org
· luajit 地址:http://luajit.org/download.html
· HttpLuaModule 地址:http://wiki.nginx.org/HttpLuaModule
1. 下载安装LuaJIT
# wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz |
# tar -xzvf LuaJIT-2.0.2.tar.gz |
OK Successfully built LuaJIT |
make [1]: Leaving directory `/usr/ local /src/LuaJIT-2.0.2/src'
|
==== Successfully built LuaJIT 2.0.2 ==== |
==== Successfully installed LuaJIT 2.0.2 to /usr/ local ====
|
2. 下载准备nginx lua模块
# wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz |
3. 安装nginx
3.1 安装
# wget http://nginx.org/download/nginx-1.4.2.tar.gz |
# tar -xzvf nginx-1.4.2.tar.gz |
//先导入环境变量,告诉nginx去哪里找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 |
3.1 常见错误
# /usr/local/nginx-1.4.2/sbin/nginx -v |
./objs/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file : No such file or directory
|
# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2 |
4. nginx lua配置
nginx配置文件加入如下配置:
location ~* ^/2328(/.*) { |
default_type 'text/plain' ;
|
content_by_lua 'ngx.say("hello, ttlsa lua")' ;
|
5. 启动测试
5.1 启动nginx
# /usr/local/nginx-1.4.2/sbin/nginx |
5.2 访问测试
# curl http://test.ttlsa.com/2328/ |
hello, ttlsa lua //使用curl测试 |
nginx lua测试截图
nginx ngx_lua的安装到此结束
转载请注明出处: http://www.ttlsa.com/html/2328.html
nginx+lua+redis构建高并发应用
ngx_lua将lua嵌入到nginx,让nginx执行lua脚本,高并发,非阻塞的处理各种请求。
url请求nginx服务器,然后lua查询redis,返回json数据。
备注:centos或者redhat系统请跳转到nginx + ngx_lua安装测试
一.安装lua
# apt- get install liblua5. 1 -dev
|
# apt- get install liblua5. 1 -socket2
|
二.安装nginx
# apt- get install git-core
|
# git clone https: //github.com/simpl/ngx_devel_kit.git
|
# git clone https: //github.com/chaoslawful/lua-nginx-module.git
|
# git clone https: //github.com/agentzh/redis2-nginx-module.git
|
# git clone https: //github.com/agentzh/set-misc-nginx-module.git
|
# git clone https: //github.com/agentzh/echo-nginx-module.git
|
# git clone https: //github.com/catap/ngx_http_upstream_keepalive.git
|
# apt- get install libpcre3 libpcre3-dev libltdl-dev libssl-dev libjpeg62 libjpeg62-dev libpng12- 0 libpng12-dev libxml2-dev libcurl4-openssl-dev libmcrypt-dev autoconf libxslt1-dev libgd2-noxpm-dev libgeoip-dev libperl-dev -y
|
# wget http: //nginx.org/download/nginx-1.0.8.tar.gz
|
# tar zxvf nginx- 1.0 . 8 .tar.gz
|
请发表评论