Fork me on GitHub
代码改变世界

nginx lua 开发笔记

2016-04-18 15:39  freefei  阅读(314)  评论(0编辑  收藏  举报

获取 在lua代码中获取 location 正则的参数对应的变量


// location 
   location ~/lua_http_2/(\w*.+) {  }


// lua
          local vars=ngx.var; // 数组中存的是 location 参数值
          local url="/zhuanfa/"..vars[1];
         
          local resp = ngx.location.capture(url, {
              method = ngx.HTTP_GET,
              body = body,
              args = {q="info.php"}
          })
          if resp.body then
              ngx.say(resp.body);            
          end

网页显示输出

  • default_type 'text/html'; 表示在网页中输出 html ;如果没有 程序执行会下载文件
@ https://github.com/ranmufei

守望者舆情监控

守望者舆情监控系统