ngx.exec出错

来源:4-34 Nginx与Lua的开发_实战场景灰度发布场景演示4

蜥蜴

2018-04-25

lua entry thread aborted: runtime error: /opt/app/lua/dep.lua:26: attempt to call ngx.exec after sending out response headers

stack traceback:

coroutine 0:

[C]: in function 'exec'

/opt/app/lua/dep.lua:26: in function </opt/app/lua/dep.lua:1>,


写回答

1回答

Jeson

2018-04-27

/opt/app/lua/dep.lua 这个文件的第26行,看下什么内容,方便的话贴出来我瞅瞅

0
1
醉李白
1 #!/usr/bin/lua 2 clientIP = ngx.req.get_headers()["X-Real-IP"] 3 if clientIP == nil then 4 clientIP = ngx.req.get_headers()["X_Forwarded_For"] 5 end 6 if clientIP == nil then 7 clientIP = ngx.var.remote_addr 8 end 9 local memcached = require "resty.memcached" 10 local memc,err = memcached:new() 11 if not memc then 12 ngx.say("failed to instantiate memc",err) 13 return 14 end 15 local ok,err = memc:connect("127.0.0.1",11211) 16 if not ok then 17 ngx.say("failed to connect: ",err) 18 return 19 end 20 local res,flags,err = memc:get(clientIP) 21 ngx.say("value key : ",res,clientIP) 22 if err then 23 ngx.say("failed to get clientIP",err) 24 end 25 if res == "1" then 26 ngx.exec("@server_test") 27 end 28 ngx.exec("@server") 我也是一模一样的报错
2019-09-15
共1条回复

Nginx入门到实践-Nginx中间件应用+搭建Webserver架构

中间件、负载均衡、应用层安全防护、动静分离、Nginx+LUA开发等

4183 学习 · 908 问题

查看课程