编译 Nginx 需要先准备好下面的这些工具,如果不确定是否已安装,可以在编译的时候根据出现的错误提示再进行安装
yum install -y gcc g++ gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
Nginx 支持 Lua 需要依赖 LuaJIT-2.0.4.tar.gz,ngx_devel_kit,lua-nginx-module,下面介绍具体的编译过程 (都下载到 /root 目录)
下载安装 LuaJIT-2.0.4.tar.gz
wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar xzvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make install PREFIX=/usr/local/luajit
# 添加环境变量
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
下载解压 ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz
下载解压 lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzvf v0.10.8.tar.gz
下载安装 nginx-1.10.3.tar.gz
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -xzvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
# 注意ngx_devel_kit和lua-nginx-module 以实际解压路径为准
./configure --add-module=/root/ngx_devel_kit-0.3.0 --add-module=/root/lua-nginx-module-0.10.8
make -j2
make install
Nginx 被安装到了 /usr/local/nginx,配置文件为 /usr/local/nginx/conf/nginx.conf
验证
- 将 nginx 做成命令: ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
- /usr/local/nginx/conf/nginx.conf 中添加 Lua 测试代码
location /lua {
default_type 'text/html';
content_by_lua 'ngx.say("hello world");';
}
启动 Nginx: sudo nginx curl http://localhost/lua 输出 hello world 则说明 Nginx 支持 Lua
网友评论