Skip to content

Instantly share code, notes, and snippets.

@kujiy
Forked from hiboma/nginx.conf
Created July 31, 2019 16:46
Show Gist options
  • Save kujiy/264d5a7dd91275dc091b00ecff8bd3e4 to your computer and use it in GitHub Desktop.
Save kujiy/264d5a7dd91275dc091b00ecff8bd3e4 to your computer and use it in GitHub Desktop.
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment