lua entry thread aborted: runtime error: attempt to concatenate field 'cookie_sessionid' (a nil value)
lua entry thread aborted: runtime error: attempt to concatenate field 'cookie_sessionid' (a nil value)
/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 有什么问题?
ngx.var.cookie_sessionid
是 nil
,正如消息告诉您的那样,您不能连接(即 ..
)那个。提供 if
检查逻辑来处理这种情况,或者如果您同意使用空字符串作为默认值,则使用 ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid or "")
。
/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 有什么问题?
ngx.var.cookie_sessionid
是 nil
,正如消息告诉您的那样,您不能连接(即 ..
)那个。提供 if
检查逻辑来处理这种情况,或者如果您同意使用空字符串作为默认值,则使用 ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid or "")
。