Suppose we have several identical nodes which are the application servers of some n-tier service. And suppose we use Apache ZooKeeper to keep all the config\'s of our distribute
Please try Nginx-Clojure. We can use a clojure/java/groovy rewrite handler to access zookeeper then update some nginx variables to dynamically change proxy target. e.g.
In nginx.conf
set $mytarget "";
location / {
rewrite_handler_type java;
## We will change $mytarget in MyRewriteHandler
rewrite_handler_name my.MyRewriteHandler;
proxy_pass $mytarget;
}
In MyRewriteHandler.java
public static class MyRewriteHandler implements NginxJavaRingHandler {
@Override
public Object[] invoke(Map request) {
//access zookeeper
...............
//change nginx variable mytarget
((NginxJavaRequest)request).setVaraible("mytarget", "http://some-host-or-url");
}