Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created May 16, 2014 08:58
Show Gist options
  • Save ChinaXing/de4107fc8a9145c1367a to your computer and use it in GitHub Desktop.
Save ChinaXing/de4107fc8a9145c1367a to your computer and use it in GitHub Desktop.
nginx-domain-forwarding
-- yunxing.cyx @ 2014-04-09
-- yunxing.cyx @ 2014-05-16 fix bug , use ngx.var.host to fetch domain name
-- load from pesystem
local host_header = ngx.var.host
local resp = ngx.location.capture("/forwarding/domain/host/" .. host_header)
if resp.status ~= 200 then
ngx.header.content_type = 'text/plain'
ngx.say("forwarding target for " .. host_header .. " can not be found !")
ngx.exit(ngx.HTTP_OK)
end
-- parse
loadstring("forwarding_info = " .. resp.body)()
if forwarding_info.success then
ngx.var.dest_host = forwarding_info.data.hostName
ngx.var.dest_port = forwarding_info.data.port
return
end
-- error
ngx.header.content_type = 'text/plain'
ngx.say("failure to get forwarding target " .. host_header .. " : " .. forwarding_info.data)
ngx.exit(ngx.HTTP_OK)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment