Is there any way to configure nginx (or other quick reverse proxy) dynamically?

后端 未结 8 1867
旧巷少年郎
旧巷少年郎 2021-02-04 02:12

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

8条回答
  •  花落未央
    2021-02-04 02:56

    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");
            }
    

提交回复
热议问题