nginx 下lua模块实现功能转发 - Go语言中文社区

nginx 下lua模块实现功能转发


$request_body你的if语句执行时,变量可能没有被读入内存。

建议的替代方法是使用lua支持或使用echo模块编译nginx并运行echo_request_body

I found the solution.

I did following changes in nginx(open resty) config file 

upstream algoapp {
   server 127.0.0.0.1:543;
}
upstream main {
   server 127.0.0.1:443;
}

location /rest/ws/login {
   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-Server $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Url-Scheme $scheme;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header Host $http_host;
   proxy_redirect off;
   if ($request_method = OPTIONS ) {
   proxy_pass https://127.0.0.1:543;
   }
   if ($request_method = POST ) {
   set $upstream '';
   access_by_lua '
   ngx.req.read_body()
   local data = ngx.req.get_body_data()
   local  match = ngx.re.match(ngx.var.request_body, "appId")
   if match then
      ngx.var.upstream = "algoapp"
   else
   ngx.var.upstream = "main"
   end
   ';
   proxy_pass https://$upstream;
   }
   }
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_39891030/article/details/83958925
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 19:59:44
  • 阅读 ( 1141 )
  • 分类:Go Web框架

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢