Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx+Lua+Redis で動的upstream
worker_processes 1;
error_log /dev/stderr debug;
events {
worker_connections 256;
}
http {
server {
listen 8888;
server_name localhost;
location / {
set $upstream "";
rewrite_by_lua '
local res = ngx.location.capture("/redis")
if res.status == ngx.HTTP_OK then
ngx.var.upstream = res.body
else
ngx.exit(ngx.HTTP_FORBIDDEN)
end
';
proxy_pass http://$upstream;
}
location /redis {
internal;
set $redis_key $host;
redis_pass 127.0.0.1:6379;
default_type text/html;
}
}
}
@hiboma

This comment has been minimized.

Copy link
Owner Author

@hiboma hiboma commented Jan 24, 2012

$ redis-cli
redis 127.0.0.1:6379> set sushi.blog.com 192.168.0.1:8888
OK

@hiboma

This comment has been minimized.

Copy link
Owner Author

@hiboma hiboma commented Jan 24, 2012

$ curl -i http://127.0.0.1:8888/
HTTP/1.1 403 Forbidden

@hiboma

This comment has been minimized.

Copy link
Owner Author

@hiboma hiboma commented Jan 24, 2012

curl -i -H 'Host: sushi.blog.com' http://127.0.0.1:8888/
HTTP/1.1 200 OK

@hiboma

This comment has been minimized.

Copy link
Owner Author

@hiboma hiboma commented Jan 24, 2012

エラー処理とかキャッシュとかそういうのははしょってます

@hiboma

This comment has been minimized.

Copy link
Owner Author

@hiboma hiboma commented Jan 24, 2012

寿司がくいたい

@kujiy

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment