DeemOpen / zkui

A UI dashboard that allows CRUD operations on Zookeeper.
2.36k stars 977 forks source link

How do I run this behind an nginx proxy? #14

Open dwu-zingbox opened 8 years ago

dwu-zingbox commented 8 years ago

nginx is configured as,

        location /zkui {
                proxy_pass http://localhost:8090;
        }

But zkui will reference from /. Is there a config I can force it referencing to /zkui?

gitorko commented 8 years ago

Can you try this?

ProxyRequests off ProxyPreserveHost on

ProxyPass /zkui/ http://hostname:9090/ ProxyPassReverse /zkui/ http://mydomain/

dwu-zingbox commented 8 years ago

Thanks responding. The difficulty is the server side routing, /zkui. zkui think the server is at root so link sent to FE are all reference to root. Nginx won't be able to route these request to zkui. So the basic question is how to naturally run zkui at different path like localhost:9090/zkui.

I've found solution and almost ready to do a pull request.

My final nginx confi is,

        location /zkui {
                proxy_pass http://localhost:9090/zkui;
        }

Added configuration as

baseURL=/zkui/

Series files got modified for example Main.java

 66         WebAppContext servletContextHandler = new WebAppContext();
 67         String serverBaseURL;
 68         if ( (serverBaseURL = System.getenv("ZKUI_BASEURL")) == null ) {
 69             if ( (serverBaseURL = globalProps.getProperty("baseURL")) == null ) {
 70                 serverBaseURL = "/";
 71             }
 72         }
 73         servletContextHandler.setContextPath(serverBaseURL);
 74         //servletContextHandler.setResourceBase("src/main/resources/" + webFolder);
 75         servletContextHandler.setResourceBase("resources/" + webFolder);

setContextPath() would take care of server routing naturally. New logic would take baseURL setting in the config file or from system env ZKUI_BASEURL. Then modify all controllers to send request to relative path instead of absolute path.

Line 75 was added to fix another problem I found when building docker image. Resources weren't loaded into docker images.

I plan to add some more configuration items, like server port and zk servers to ENV before I do a pull request.

aseev-xx commented 7 years ago

@dwu-zingbox good idea

michaelburn commented 6 years ago

I'm also interested in running zkui with reverse-proxy nginx. @dwu-zingbox Thank you for your work! Can you share the other neccessary modifications with me?

shyimo commented 4 years ago

@michaelburn @dwu-zingbox Hi guys. what are the other changes you made in order to make this work ? i try myself but it didn't work out for me..

yoholiao commented 3 years ago

@michaelburn @dwu-zingbox Hi guys. what are the other changes you made in order to make this work ? i try myself but it didn't work out for me..

i do this: nginx:

    location /zkui/ {
        proxy_pass http://127.0.0.1:9090/;
        proxy_redirect http://127.0.0.1:9090/ /zkui/;
    }

index.html

<!-- src/main/resources/webapp/html/index.html -->
<head>
   <meta http-equiv="refresh" content="0;url=/zkui/home"/> 
   <base href="/zkui/" />
</head>

then all other html remove / in href.

<form method="post" action="/history" role="form"  class="form-horizontal">
<form method="post" action="history" role="form"  class="form-horizontal">

wish this may help you

ntungatkar commented 2 years ago

I changed Main.java. Also updated the controllers. Then updated the index.html Then updated all the html files with relative paths. but still the css & js files won't load correctly.

What else do I need to change?