nginx: support pass for redis. bug fixed

This commit is contained in:
Alexey Bannov 2023-09-29 17:26:43 +03:00
parent e34a80fa9e
commit 2987cf797b

View File

@ -98,17 +98,27 @@ server {
local red = redis:new()
local redis_host = "127.0.0.1"
local redis_port = 6379
local redis_pass = ""
red:set_timeout(1000) -- 1 second
local ok, err = red:connect(redis_host, redis_port)
if not ok then
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
return
end
if redis_pass ~= "" then
local res, err = red:auth(redis_pass)
if not res then
ngx.log("failed to authenticate: ", err)
return
end
end
local csp, err = red:hget(key, "data")
if csp == ngx.null then
if csp == ngx.null or not csp then
ngx.log(ngx.ERR, "failed to get redis key: ", err)
else
ngx.header.Content_Security_Policy = csp