【问题标题】:lua entry thread aborted: runtime error: attempt to concatenate field 'cookie_sessionid' (a nil value)lua 入口线程中止:运行时错误:尝试连接字段“cookie_sessionid”(一个零值)
【发布时间】:2016-07-26 22:45:32
【问题描述】:

/etc/nginx/sites-enabled/default

location /pine {
    add_header Access-Control-Allow-Origin http://localhost:6285;
    add_header Access-Control-Allow-Credentials true;
    access_by_lua_file /home/akuznetsov/auth.lua;
    proxy_pass http://localhost:9100;
}

auth.lua(版本 1,工作正常):

ngx.req.set_header('x-user-id', ngx.var.cookie_sessionid)

auth.lua(版本 2,不工作):

ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid)

/var/log/nginx/error.log 我得到这个错误:

2016/04/06 16:13:10 [error] 14183#0: *1 lua entry thread aborted: runtime error: /home/akuznetsov/auth.lua:2: attempt to concatenate field 'cookie_sessionid' (a nil value)
stack traceback:
coroutine 0:
/home/akuznetsov/auth.lua:2: in function </home/akuznetsov/auth.lua:1>, client: 127.0.0.1, server: localhost, request: "OPTIONS /pine HTTP/1.1", host: "localhost", referrer: "http://localhost:6285/chart/kjckCBcG/?pine=http://localhost/pine"

concat 有什么问题?

【问题讨论】:

  • 这不是一个调试服务......和WTF? concat有什么问题?也不是一个合适的问题。请注意礼貌。

标签: nginx lua cors reverse-proxy


【解决方案1】:

ngx.var.cookie_sessionidnil,正如消息告诉你的那样,你不能连接(即..)。提供if 逻辑检查以处理这种情况或使用ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid or "") 如果您可以默认使用空字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2021-01-01
    • 2016-06-21
    • 2021-05-15
    • 2015-07-18
    • 2020-08-02
    • 2016-09-19
    相关资源
    最近更新 更多