【发布时间】:2020-03-20 08:22:46
【问题描述】:
我有如下的nginx配置文件:
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
init_by_lua 'cjson = require("cjson")';
server {
listen 8080;
location / {
default_type text/html;
content_by_lua '
json_text = "{ \"aaa\": \"bar\" }"
local message = cjson.decode(json_text)
ngx.say(message)
';
}
}
}
当我访问 url http://localhost:8080 时,我收到错误:
content_by_lua(nginx.conf:17): in main chunk, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
2019/11/25 15:03:12 [error] 36979#684497: *2 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:17):2: attempt to call global 'aaa' (a nil value)
它抱怨调用 global 'aaa' 但我正在做的只是解码一个 json 字符串。我在脚本中有什么错误吗?
【问题讨论】: