2016-04-06 22 views
-1

的/ etc/nginx的/啓用的站點 - /默認的Lua Nginx的級聯錯誤

 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) 

權威性。 lua(version 2,not working):

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有什麼錯誤?

+2

這不是一個調試服務...和WTF? concat有什麼錯誤?也不是一個合適的問題。請接受一些禮節。 – Piglet

回答

1

ngx.var.cookie_sessionidnil正如消息告訴你,你不能連接(即..)。提供if檢查邏輯來處理這種情況,或者使用ngx.req.set_header('x-user-id', 'session:' .. ngx.var.cookie_sessionid or ""),如果您將空字符串用作默認值即可。

0

尤里卡!瀏覽器首先發送OPTIONS請求沒有cookie,但第二個請求(POST,例如)它。我看到nginx代理背後的答案,在我看來,這一切都很好。