Nginx dynamic upstream configuration / routing
Posted
by
Dan Sosedoff
on Server Fault
See other posts from Server Fault
or by Dan Sosedoff
Published on 2012-03-29T00:21:08Z
Indexed on
2012/03/29
5:31 UTC
Read the original article
Hit count: 660
I was experimenting with dynamic upstream configuration for nginx and cant find any good solution to implement upstream configuration from third-party source like redis or mysql.
The idea behind it is to have a single file configuration in primary server and proxy requests to various app servers based on environment conditions. Think of dynamic deployments where you have X servers that are running Y workers on different ports. For instance, i create a new app and deploy. App manager selects a server and then rolls out a worker (Ruby/PHP/Python) and then reports the ip:port to the central database with status "up". At this time when i go to the given url nginx should proxy all requests to the specified ip:port upstream. The whole thing is pretty similar to what heroku does, except this proof-of-concept is not supposed to be production ready, mostly for internal needs.
The easiest solution i found was using resolver with ruby-based DNS server. It works, nginx gets the IP address correctly, but the only problem is that you cant define port number for that IP.
Second solution (which i havent tried yet) is to roll something else as a proxy server, maybe written in Erlang. In this case we need to use something to serve static content.
Any ideas how to implement this in more flexible and stable way?
P.S. Some research options:
© Server Fault or respective owner