nginx+lua 实现URL重定向(根据传入的参数条件)

发布于:2024-07-15 ⋅ 阅读:(115) ⋅ 点赞:(0)

程序版本说明

程序 版本 URL
nginx 1.27.0 https://nginx.org/download/nginx-1.27.0.tar.gz
ngx_devel_kit v0.3.3 https://github.com/simpl/ngx_devel_kit/archive/v0.3.3.tar.gz
luajit v2.1 https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20240626.tar.gz
lua-nginx-module v0.10.26 https://github.com/openresty/lua-nginx-module/archive/v0.10.26.tar.gz
lua-resty-core v0.1.28 https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.28.tar.gz
lua-resty-lrucache v0.12 https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.12.tar.gz
lua-resty-http v0.17.2 https://github.com/ledgetech/lua-resty-http/archive/refs/tags/v0.17.2.tar.gz
lua-cjson 2.1.0.9 https://github.com/openresty/lua-cjson/archive/refs/tags/2.1.0.9.tar.gz

安装Lua

从https://github.com/openresty/luajit2下载安装

# git clone https://github.com/openresty/luajit2.git
cd /root/soft
wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20240626.tar.gz
tar -xzvf v2.1-20240626.tar.gz
cd luajit2-2.1-20240626
make && make install
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

添加环境变量

vim /etc/profile
#最后两行添加如下内容:
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
下载解压ngx_devel_kit
cd /root/soft
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.3.tar.gz
tar -xzvf v0.3.3.tar.gz

下载解压lua-nginx-module
cd /root/soft
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.26.tar.gz
tar -xzvf v0.10.26.tar.gz
# lua-nginx-module-0.10.16 以后都需要 lua-resty-core和lua-resty-lrucache**
wget https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.28.tar.gz
tar -xzvf v0.1.28.tar.gz
cd lua-resty-core-0.1.28
make && make install LUA_LIB_DIR=/usr/local/share/lua/5.1

wget https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.12.tar.gz
tar -xzvf v0.12.tar.gz
cd lua-resty-lrucache-0.12