zoukankan      html  css  js  c++  java
  • nginx + lua 根据post请求参数做转发

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


            location @user_profile_api12 {

             content_by_lua_block {
                     ngx.say("xxxx")
             }
             }


            location @user_profile_api3 {

             content_by_lua_block {
                     ngx.say("hahahah")
             }
            }



    lua/dispatch.lua

    -------------------------------

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

    if arg ~= nil then
       local json = require("cjson")
       local jsonObj = json.decode(arg)
       local profile = jsonObj['query']['user_profile']
       local years = jsonObj['query']['year_id']

      if years ~= nil and profile ~= nil and profile[1] == 'bought_record' then
             ngx.exec('@user_profile_api3') 
       elseif profile ~= nil and profile[1] == 'xubao' then
             ngx.exec('@user_profile_api3')
       else 
             ngx.exec('@user_profile_api12')
       end
    end

  • 相关阅读:
    SugarCRM 主表自定义字段日期型
    算法导论46 VLSI芯片测试
    算法导论14.18
    算法导论13.24
    poj1980 Unit Fraction Partition **
    算法导论5.12
    算法导论76 对区间的模糊排序
    红黑树(redblack tree)算法,附AVL树的比较
    poj1856 Sea Battle *
    算法导论42 找出所缺的整数
  • 原文地址:https://www.cnblogs.com/maoxiangyi/p/11611383.html
Copyright © 2011-2022 走看看