ngx.exec出错
来源:4-28 Nginx与Lua的开发_Nginx与Lua的开发环境
我去年买了个表
2018-06-29
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"
1回答
-
Jeson
2018-07-02
这个脚本是执行到这报的错误“ 38 ngx.exec("@client1")”,这个地方你需要打印出来分析调试下。是不是@client1没有定义?
012018-07-04
相似问题