Lua Nginx Redis get requested domain? -
so right have piece of lovely code
server { listen 80; location /{ set $target ''; access_by_lua ' local key = ngx.var.http_host if not key ngx.log("no request url found") return ngx.exit(400) end local redis = require "resty.redis" local red = redis:new() red:set_timeout(1000) -- 1 second local ok, err = red:connect("<server_ip>", <server_port>) if not ok ngx.log("failed connect reddis server") return ngx.exit(500) end local res, err = red:auth("<pass>") if not res ngx.say("failed authenticate redis server") return ngx.exit(500) end local host, err = red:get(key) if not host ngx.log("failed retrieve redis key") return ngx.exit(500) end if host == ngx.null ngx.log("no host found") return ngx.exit(400) end ngx.var.target = host '; proxy_pass http://$target; } }
so in redis have key set domain name example.com , have value set backend ip or url in case google.com
now when request comes through plan whatever url user put in, search redis key , value, value , pass onto proxy_pass
am doing wrong?
i have installed nginx-extras , using debian 8
Comments
Post a Comment