近期有多次安装配置nginx以及lua模块的需求,特此总结一下,以备后续参考
- 下载所需文件
# 默认都放到/home/finance/software/路径下
# nginx 1.18.0
https://nginx.org/download/nginx-1.18.0.tar.gz
# nginx sticky module,可选
https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
# upstream check module,可选
https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
# 以下为lua相关文件
# LuaJIT 2.1(2.0或者2.1都是支持的,官方推荐2.1)
wget http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
# ngx_devel_kit(NDK)模块
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz --no-check-certificate
# lua nginx module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz --no-check-certificate
- 安装LuaJIT
cd /home/finance/software/
tar zxf LuaJIT-2.1.0-beta2.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit
ln -sf luajit-2.1.0-beta2 /usr/local/luajit/bin/luajit
# 修改系统环境变量
echo 'export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1' >> /etc/profile
echo '/usr/local/lib
/usr/local/luajit/lib' >> /etc/ld.so.conf
# 重新加载配置,立即生效
ldconfig
- 解压NDK和lua nginx module,无需安装
cd /home/finance/software/
tar -zxvf v0.3.0.tar.gz
cd /home/finance/software/
tar -xzvf v0.10.13.tar.gz
- 安装配置nginx 1.18.0
# 安装依赖
yum install -y gcc pcre-devel openssl-devel zlib-devel
# 解压两个可选插件以及nginx安装包
cd /home/finance/software/
tar -xzvf nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz
unzip nginx_upstream_check_module-master.zip
tar -xf nginx-1.18.0.tar.gz
# 编译安装nginx
cd nginx-1.18.0/
./configure --prefix=/opt/nginx \
--sbin-path=/opt/nginx/sbin/nginx \
--conf-path=/opt/nginx/conf/nginx.conf \
--error-log-path=/home/finance/Logs/nginx/error.log \
--http-log-path=/home/finance/Logs/nginx/access.log \
--pid-path=/opt/nginx/var/nginx.pid \
--lock-path=/opt/nginx/var/nginx.lock \
--http-client-body-temp-path=/dev/shm/nginx_temp/client_body \
--http-proxy-temp-path=/dev/shm/nginx_temp/proxy \
--http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi \
--user=finance \
--group=finance \
--with-cpu-opt=pentium4F \
--without-select_module \
--without-poll_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_stub_status_module \
--without-http_ssi_module \
--without-http_userid_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--without-http_geo_module \
--with-stream_realip_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-http_ssl_module \
--add-module=/home/finance/software/nginx-goodies-nginx-sticky-module-ng-08a395c66e42 \
--add-module=/home/finance/software/nginx_upstream_check_module-master \
--add-module=/home/finance/software/ngx_devel_kit-0.3.0 \
--add-module=/home/finance/software/lua-nginx-module-0.10.13
# 安装到/opt/,如果以及存在,备份老的nginx之后再进行
make && make install
# 创建依赖的temp文件夹
mkdir -pv /dev/shm/nginx_temp/
mkdir -pv /home/finance/Logs/nginx
# 把以下几行测试Lua的配置加到/opt/nginx/conf/nginx.conf的location /上面
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("Hello Lua!")';
}
# 验证nginx配置,并启动
/opt/nginx/sbin/nginx -t
/opt/nginx/sbin/nginx
- 验证lua是否安装成功
# 浏览器直接访问http://<ip>/hello_lua , 或者curl
[root@interrupt_224_17 conf]# curl http://127.0.0.1:80/hello_lua
Hello Lua!
# 看到Hello Lua!说明lua配置成功