Last active
August 29, 2015 14:13
-
-
Save spro/2afede5e48341dfcc67b to your computer and use it in GitHub Desktop.
hipache reimplimented in lua in nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location / { | |
set $proxy_to ""; | |
access_by_lua " | |
local redis = require 'redis' | |
local red = redis:new() | |
red:connect('127.0.0.1', 6379) | |
local headers = ngx.req.get_headers() | |
local hosts = red:smembers('frontend:' .. headers['host']) | |
local chosen = hosts[math.random(#hosts)] | |
ngx.var.proxy_to = chosen | |
"; | |
proxy_pass http://$proxy_to; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment