Lua Nginx Concatenation Error -


/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 (version 1, works fine):

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

auth.lua (version 2, not working):

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

in /var/log/nginx/error.log error:

2016/04/06 16:13:10 [error] 14183#0: *1 lua entry thread aborted: runtime error: /home/akuznetsov/auth.lua:2: attempt 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" 

wtf? wrong in concat?

ngx.var.cookie_sessionid nil , message tell you, can't concatenate (i.e. ..) that. provide if check logic handle case or use ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid or "") if okay using empty string default.


Comments