下载安装LuaJIT(http://luajit.org/download.html)
cd /usr/local/src wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar zxf LuaJIT-2.0.5.tar.gz cd LuaJIT-2.0.5.tar.gz make PREFIX=/usr/local/luajit make install PREFIX=/Users/xuguangwu486/software/luajit
下载ngx_devel_kit(NDK)https://github.com/simpl/ngx_devel_kit/tags
cd /usr/local/src wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz tar -xzvf v0.2.19.tar.gz
下载最新的lua-nginx-module 模块 (https://github.com/openresty/lua-nginx-module/tags)
cd /usr/local/src wget https://github.com/openresty/lua-nginx-module/archive/v0.10.2.tar.gz tar -xzvf v0.10.2.tar.gz
nginx -V查看已经编译的配置
nginx -V
进入之前安装nginx的解压目录,重新编译安装(在nginx -V得到的配置下,加入ngx_devel_kit-0.2.19和ua-nginx-module-0.10.2的目录),最终的配置如下: 设置环境变量
export LUAJIT_LIB=/Users/xuguangwu486/software/luajit/lib export LUAJIT_INC=/Users/xuguangwu486/software/luajit/include/luajit-2.0 ./configure –prefix=/Users/xuguangwu486/software/nginx –with-http_stub_status_module –with-http_v2_module –with-http_ssl_module –with-http_gzip_static_module –with-http_realip_module –with-http_flv_module –with-openssl=/Users/xuguangwu486/software/openssl-1.0.2n –with-pcre=/Users/xuguangwu486/software/pcre-8.35 –with-pcre-jit –with-ld-opt=’-ljemalloc’ –with-ld-opt=”-Wl,-rpath,/Users/xuguangwu486/software/luajit/lib” –add-module=/Users/xuguangwu486/software/ngx_devel_kit-0.3.1rc1 –add-module=/Users/xuguangwu486/software/lua-nginx-module-0.10.12rc2
./configure –prefix=/Users/xuguangwu486/software/nginx –with-http_stub_status_module –with-http_v2_module –with-openssl=/Users/xuguangwu486/software/openssl-1.0.2n –with-pcre=/Users/xuguangwu486/software/pcre-8.35 –with-pcre-jit –with-ld-opt=”-Wl,-rpath,/Users/xuguangwu486/software/LuaJIT2.0.4/lib” –add-module=/Users/xuguangwu486/software/ngx_devel_kit-0.3.1rc1 –add-module=/Users/xuguangwu486/software/lua-nginx-module-0.10.12rc2
make -j2 make install
7.查看是否编译成功
在/usr/local/nginx/conf/nginx.conf中加入如下代码:
location /hello_lua { default_type ‘text/plain’; content_by_lua ‘ngx.say(“hello, lua”)’; } 重启nginx: service nginx restart 访问10.211.55.3/hello_lua会出现”hello, lua”表示安装成功 hello, lua