nginx安装 ngx_lua模块

 

HttpLuaModule是淘宝开发的nginx的第三方模块,能将lua语言嵌入到nginx配置中

这里我主要记录日志作用,用来记录关于用户在网站上行为的到log日志中,lua同样作为脚本语言发挥更大作用,诸如通过redis中的数据,直接返回json等格式数据相应给用户,我这里主要是存放入log中,然后做数据ETL处理,如果访问量非常大,进行离线情况下Map-reduce的分析处理。

安装包下载

nginx  地址:http://www.nginx.org
luajit 地址:http://luajit.org/download.html
HttpLuaModule 地址:http://wiki.nginx.org/HttpLuaModule
1.安装luajit
cd /usr/server/nginx
wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar -xzvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make
make install

2.安装nginx
cd /usr/server/nginx
wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar -xzvf nginx-1.4.7.tar.gz cd nginx-1.4.7 
3.导入环境变量
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

./configure --prefix=/usr/server/nginx \
--conf-path=/usr/server/nginx/nginx.conf \
--add-module=/usr/server/nginx/lua-nginx-module-0.8.6
make -j2
make install

4.检查
./sbin/nginx -t
如果出现error:
 error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 可能是./configure时--conf-path未配置,或者# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so. 5.安装pcre 安装nginx时,其实pcre第一步就要安装 为了检查是否安装,可通过 

      ./configure --prefix=/usr/server/nginx --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-http_ssl_module

 

安装nginx之前需要安装PCRE库的安装(使用root用户
最新下载地址   ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
tar –zxvf pcre-8.21.tar.gz
,解压目录为:pcre-8.21
然后进入到cd pcre-8.21,进行配置、编译、安装
配置
./configure
./config
编译
make
安装
make install

 6.测试安装成功 cd /usr/server/nginx ./sbin/nginx -t 至于nginx其它命令可通./sbin/nginx -h 常用的有 ./sbin/nginx -h help ./sbin/nginx 启动 ./sbin/nginx -t check ./sbin/nginx -s reload 重新加载 ./sbin/nginx -s quit 服务退出  7.配置nginx.conf cd /usr/server/nginx/conf vi nginx.conf location ~* ^/lua(/.*) { default_type 'text/plain'; content_by_lua 'ngx.say("hello,it's lua language")'; } 8.curl http://domail/lua/

9.nginx对于代理、负载不在本章节讨论,其实蛮简单的

10.在附件中提供nginx的lua语言用来扩展,记得联系下https://github.com/agentzh

猜你喜欢

转载自cywhoyi.iteye.com/blog/2118913
今日推荐