为什么proxy_pass会导致我的content_by_lua失效

57 views
Skip to first unread message

X A

unread,
Apr 25, 2024, 2:45:47 AMApr 25
to openresty
大佬们好,我现在写了一个lua脚本用来验证accesstoken,如果这个accesstoken没通过,nginx会返回一个401
  local jwt_obj = jwt:verify(secret, puretoken)
            ngx.log(ngx.ERR, "JWT verification result-n: ", cjson.encode(jwt_obj))
             if not jwt_obj["verified"] then
                 ngx.log(ngx.ERR, "ACCESS DENIED")
                ngx.status = ngx.HTTP_UNAUTHORIZED
                ngx.say("Unauthorized: Invalid Access Token")
                ngx.exit(ngx.HTTP_UNAUTHORIZED)
                return
            end 

之后我把他放到location块中,按照设想,如果验证通过会将请求发给后端,就是走proxy_pass,如果不通过就返回401,但是现在只要加上proxy_pass,请求似乎就不会走lua模块里的内容,直接就请求到了后端,log里面的东西也没在error.log里面打印出来
/web{
content_by_lua_block{
xxx
}
rewrite ^/npmis(/.*)$ $1 break;
}
请问这是为什么?

Junlong li

unread,
Apr 25, 2024, 7:15:14 AMApr 25
to openresty
两个只能选择一个,不能同时配置。

417132187

unread,
Apr 25, 2024, 7:15:31 AMApr 25
to Junlong li

彳余

unread,
Apr 25, 2024, 8:25:53 AMApr 25
to open...@googlegroups.com
放到 rewrite_by_lua_block 阶段或 access_by_lua_block 阶段下, 是可以的


Junlong li <zhuizhu...@gmail.com> 于2024年4月25日周四 19:15写道:
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
---
您收到此邮件是因为您订阅了Google网上论坛上的“openresty”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到openresty+...@googlegroups.com
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/openresty/96045381-467c-4f9e-9fdf-8d902c78adcfn%40googlegroups.com

X A

unread,
Apr 25, 2024, 9:49:38 PMApr 25
to open...@googlegroups.com
感谢大佬,解决了!!!牛逼!!!gpt都问不出来 access_by_lua_block,看了git上的readme才知道有这么多区别🥰

彳余 <xugu...@gmail.com> 于2024年4月25日周四 20:25写道:
您收到此邮件是因为您订阅了Google网上论坛上“openresty”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/openresty/tUviEq-_qM4/unsubscribe
要退订此群组及其所有主题,请发送电子邮件到openresty+...@googlegroups.com
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/openresty/CAJkbxHryhi2d4%3D8DsWquAHF6pohSOus_dJFXVzjt4WwuKTvVhw%40mail.gmail.com
Reply all
Reply to author
Forward
0 new messages