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

avatar
作者
猴君
阅读量:0

程序版本说明

程序版本URL
nginx1.27.0https://nginx.org/download/nginx-1.27.0.tar.gz
ngx_devel_kitv0.3.3https://github.com/simpl/ngx_devel_kit/archive/v0.3.3.tar.gz
luajitv2.1https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20240626.tar.gz
lua-nginx-modulev0.10.26https://github.com/openresty/lua-nginx-module/archive/v0.10.26.tar.gz
lua-resty-corev0.1.28https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.28.tar.gz
lua-resty-lrucachev0.12https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.12.tar.gz
lua-resty-httpv0.17.2https://github.com/ledgetech/lua-resty-http/archive/refs/tags/v0.17.2.tar.gz
lua-cjson2.1.0.9https://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 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!