请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

ngx.exec出错

  1 ngx.say("hello,lua1")

  2 

  3 local redis = require "resty.redis"

  4 local cache = redis:new()

  5 

  6 cache:set_timeout(600)

  7 

  8 local ok, err = cache:connect('127.0.0.1', 6379)

  9 ngx.say("jieguo:", ok)

 10 if not ok then

 11     ngx.say("failed to connect:", err)

 12     return

 13 end

 14 --[[

 15 local red, err = cache:auth("foobared")

 16 if not red then

 17     ngx.say("failed to authenticate: ", err)

 18     return

 19 end

 20 ]]--

 21 local local_ip = ngx.req.get_headers()["X-Real-IP"]

 22 if local_ip == nil then

 23     local_ip = ngx.req.get_headers()["x_forwarded_for"]

 24 end

 25 

 26 if local_ip == nil then

 27     local_ip = ngx.var.remote_addr

 28 end

 29 ngx.say("local_ip is : ", local_ip)

 30 local intercept = cache:get(local_ip)

 31 

 32 

 33 if intercept == local_ip then

 34     ngx.exec("@client2")

 35     return

 36 end

 37 

 38 ngx.exec("@client1")

 39 local ok, err = cache:close()

 40 

 41 if not ok then

 42     ngx.say("failed to close:", err)

 43     return

 44 end

这是我的lua脚本  出现了ngx.exec报错:

2018/06/29 17:27:26 [error] 15721#15721: *334 lua entry thread aborted: runtime error: /usr/local/nginx/huidu.lua:38: attempt to call ngx.exec after sending out response headers

stack traceback:

coroutine 0:

[C]: in function 'exec'

/usr/local/nginx/huidu.lua:38: in function </usr/local/nginx/huidu.lua:1>, client: 101.204.216.56, server: localhost, request: "GET /test/1.txt HTTP/1.1", host: "39.108.78.127:8080"


正在回答 回答被采纳积分+3

1回答

Jeson 2018-07-02 09:48:11

这个脚本是执行到这报的错误“ 38 ngx.exec("@client1")”,这个地方你需要打印出来分析调试下。是不是@client1没有定义?

0 回复 有任何疑惑可以回复我~
  • 提问者 我去年买了个表 #1
    经过调试  发现在脚本中不能出现ngx.say这个函数,只要执行了这个函数,就会报错。我解决的办法就是将我所有的ngx.say函数给注释掉
    回复 有任何疑惑可以回复我~ 2018-07-04 17:49:28
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号