mercredi 21 janvier 2015

Nginx change proxy pass dynamicly based on redis query

I am configuring a Nginx server to run a node.js websocket app on it.


We do use AWS autoscaling and need to forward users to the right server instance based on an URL wich is /get?key=somekey.


Users need to meet within the same websocket instance, so the AWS ELB or similar wont fit for us. We need to hit the right host.


"somekey" is stored in redis and holds the host value to the right server instance we want to forward the user to.


Based on "somekey" nginx should query redis for the url and change the current proxy pass settings to the value from the query result.


This is what ive done based on the redis2 documentation, but its not working at all. Any idea whats wrong here?



server {
listen 80;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location = /get {
set_unescape_uri $key $arg_key;
redis2_query get $key;
redis2_pass myredishost:6379;
}


}





Aucun commentaire:

Enregistrer un commentaire