强烈推荐使用ngx_openresty的捆绑包:NGINX, ngx_lua, LuaJIT 2.0/2.1 (或者可选的标准 Lua 5.1解释器),
以及一揽子强劲、好用的 NGINX 模块。
使用一个简单的命令就可以完成基础安装:./configure --with-luajit && make && make install
。
当然,ngx_lua 也可以手动的编译到 NGINX 中:
- 安装LuaJIT 2.0 或 2.1 (推荐) 或 Lua 5.1 (Lua 5.2 暂时还不支持)。 LuaJIT可从 The LuaJIT project website 获取, Lua 5.1可从 Lua project website 获取。
- 下载最新版本的 ngx_devel_kit (NDK)开发模块 这里 。
- 下载最新版本的 ngx_lua 这里 。
- 下载最新版本的 NGINX 这里 (查看 Nginx 兼容列表)。
源码编译本模块:
wget 'http://nginx.org/download/nginx-1.7.10.tar.gz'
tar -xzvf nginx-1.7.10.tar.gz
cd nginx-1.7.10/
# tell nginx's build system where to find LuaJIT 2.0:
export LUAJIT_LIB=/path/to/luajit/lib
export LUAJIT_INC=/path/to/luajit/include/luajit-2.0
# tell nginx's build system where to find LuaJIT 2.1:
export LUAJIT_LIB=/path/to/luajit/lib
export LUAJIT_INC=/path/to/luajit/include/luajit-2.1
# or tell where to find Lua if using Lua instead:
#export LUA_LIB=/path/to/lua/lib
#export LUA_INC=/path/to/lua/include
# Here we assume Nginx is to be installed under /opt/nginx/.
./configure --prefix=/opt/nginx \
--with-ld-opt="-Wl,-rpath,/path/to/luajit-or-lua/lib" \
--add-module=/path/to/ngx_devel_kit \
--add-module=/path/to/lua-nginx-module
make -j2
make install
English source:
It is highly recommended to use the ngx_openresty bundle that bundles Nginx, ngx_lua, LuaJIT 2.0/2.1 (or the optional standard Lua 5.1 interpreter), as well as a package of powerful companion Nginx modules. The basic installation step is a simple command: ./configure --with-luajit && make && make install
.
Alternatively, ngx_lua can be manually compiled into Nginx:
- Install LuaJIT 2.0 or 2.1 (recommended) or Lua 5.1 (Lua 5.2 is not supported yet). LuaJIT can be downloaded from the the LuaJIT project website and Lua 5.1, from the Lua project website. Some distribution package managers also distribute LuajIT and/or Lua.
- Download the latest version of the ngx_devel_kit (NDK) module HERE.
- Download the latest version of ngx_lua HERE.
- Download the latest version of Nginx HERE (See Nginx Compatibility)
Build the source with this module:
wget 'http://nginx.org/download/nginx-1.7.10.tar.gz'
tar -xzvf nginx-1.7.10.tar.gz
cd nginx-1.7.10/
# tell nginx's build system where to find LuaJIT 2.0:
export LUAJIT_LIB=/path/to/luajit/lib
export LUAJIT_INC=/path/to/luajit/include/luajit-2.0
# tell nginx's build system where to find LuaJIT 2.1:
export LUAJIT_LIB=/path/to/luajit/lib
export LUAJIT_INC=/path/to/luajit/include/luajit-2.1
# or tell where to find Lua if using Lua instead:
#export LUA_LIB=/path/to/lua/lib
#export LUA_INC=/path/to/lua/include
# Here we assume Nginx is to be installed under /opt/nginx/.
./configure --prefix=/opt/nginx \
--with-ld-opt="-Wl,-rpath,/path/to/luajit-or-lua/lib" \
--add-module=/path/to/ngx_devel_kit \
--add-module=/path/to/lua-nginx-module
make -j2
make install