location中使用rewrite_by_lua导入lua脚本后,if条件语句失效

1.问题描述:

就是在我的上一篇文章中,研究如何“使用nginx + lua脚本 + redis进行token鉴权”时,遇到一个大坑。nginx的location中使用rewrite_by_lua来导入lua脚本后,if条件语句失效了,到那时尝试了很多方法。最开始以为自己写错变量,符号写错,还为此删除Openresty重新安装了一遍,结果发现还是一样。在location中定义的变量,经过lua脚本修改后,if语句失效了。

2.遇坑时的代码
2.1在nginx.conf的location配置
 #匹配下载请求前缀, 进行token鉴权
location ~ /download/files/.*?/data {
    set $backend '';
    default_type 'text/html';
    rewrite_by_lua_file  lua-resty-redis/lib/resty/token.lua;
    #echo 可以打印变量$backend出来
    echo $backend;
    if ( $backend = "download"){
       proxy_pass  http://download;
       break;
    }
    if ( $backend  =  "failure"){
       rewrite  ^/  /return.html;
   }
 }
2.2 在location中引入的token.lua
local var = ngx.var
local arg 
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值