最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx Lua 根據(jù)參數(shù)請求轉(zhuǎn)發(fā)的實現(xiàn)

 更新時間:2024年10月10日 10:17:38   作者:tianv5  
本文介紹了如何使用Nginx和Lua腳本實現(xiàn)基于參數(shù)的請求轉(zhuǎn)發(fā),文章詳細說明了配置方法,并提供了示例代碼,幫助讀者理解如何通過NginxLua模塊根據(jù)請求參數(shù)將流量轉(zhuǎn)發(fā)到不同后端服務(wù),這種方法有助于實現(xiàn)靈活的負載均衡和動態(tài)內(nèi)容處理

環(huán)境安裝

mkdir /usr/local/LuaJIT 
cd /usr/local/LuaJIT 
wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar -xvf LuaJIT-2.0.2.tar.gz

export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0

mkdir /usr/local/nginx
cd /usr/local/nginx
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
wget http://nginx.org/download/nginx-1.12.1.tar.gz 
tar -xvf v0.3.0.tar.gz
tar -xvf v0.10.9rc7.tar.gz
tar -xvf nginx-1.12.1.tar.gz

cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.9rc7

make 
make install

驗證

vi conf/nginx.conf

location /hello{
        default_type 'text/plain';
        content_by_lua 'ngx.say("hello,lua")';
    }


# 啟動
sbin/nginx 

# 驗證,返回 hello,lua 安裝成功
curl 127.0.0.1:80/hello

nginx lua 轉(zhuǎn)發(fā)

       location /aa {
            internal;
            default_type 'text/plain';
            content_by_lua 'ngx.say("AAAAA")';
        }
 
       location /bb {
            internal;
            default_type 'text/plain';
            content_by_lua 'ngx.say("BBBBB")';
        }


        location /dis {
             content_by_lua_file "lua/dis.lua";
         }

# lua腳本 dis.lua

local request_method = ngx.var.request_method
local arg=nil
if request_method == "GET" then
         arg = ngx.req.get_uri_args()['name']
elseif request_method == "POST" then
         ngx.req.read_body()
         arg = ngx.req.get_post_args()['name']
end

if arg == "gg" then
    ngx.exec('/aa')
else
    ngx.exec('/bb')
# 測試
curl 127.0.0.1:80/dis?name=gg
curl 127.0.0.1:80/dis?name=mm
curl 127.0.0.1:80/dis

 到此這篇關(guān)于Nginx Lua 根據(jù)參數(shù)請求轉(zhuǎn)發(fā)的實現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx Lua參數(shù)請求轉(zhuǎn)發(fā)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

甘孜县| 桂阳县| 彰化市| 平阴县| 滨海县| 黄平县| 岳阳县| 玉屏| 视频| 济源市| 万全县| 广宗县| 永福县| 阿图什市| 张家界市| 本溪市| 修武县| 策勒县| 蒙山县| 华阴市| 慈溪市| 莱州市| 苍梧县| 镇巴县| 阳城县| 伊宁市| 桃江县| 武穴市| 兴业县| 周口市| 惠来县| 迭部县| 乌苏市| 高陵县| 衢州市| 集安市| 义乌市| 塘沽区| 呈贡县| 田阳县| 普陀区|