nginx 与 lua
nginx使用lua需要依赖lua_nginx_module。
编译安装前需要下载luajit,ngx_devel_kit, lua_nginx_module, pcre, nginx source
luajit : http://luajit.org/download/LuaJIT-2.0.3.tar.gz
ngx_devel_kit: https://github.com/simpl/ngx_devel_kit/tags
lua_nginx_module: https://github.com/chaoslawful/lua-nginx-module/tags
pcre: https://sourceforge.net/projects/pcre/files/pcre/
- 安装luajit
1 wget http://luajit.org/download/LuaJIT-<VERSION>.tar.gz 2 tar zxvf LuaJIT-<VERSION>.tar.gz 3 cd LuaJIT-<VERSION> 4 make 5 make install
- 更新环境变量
1 export LUAJIT_LIB=/usr/local/lib 2 export LUAJIT_INC=/usr/local/include/luajit-<VERSION>
- 安装pcre
1 cd ~/Downloads/pcre-1.8 2 ./configure 3 make 4 make install
- 编译nginx
1 cd ~/Downloads/nginx 2 ./configure --prefix=/opt/nginx --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.9.9 --without-http_gzip_module 3 make -j2 4 make install
-
编辑nginx.conf,server段加入如下代码
1 location /hello { 2 default_type 'text/plain'; 3 content_by_lua 'ngx.say("hello, lua")'; 4 }
- 启动nginx
/opt/nginx/sbin/nginx
如果出现***.so.* notfound,需要在/etc/ld.so.conf.d/目录里新建usr_local_lib.conf文件,文件中第一行加入/usr/local/lib.保存之后shell中执行ldconfig。之后重启nginx即可