Reverse proxy Kibana


(Abhijitdeka11) #1

Hi,
I am embedding kibana inside my application which has other features also.I use reverse proxy to do this mapping.
So,whenever I hit this URL /analytics/* all calls are redirected to kibana server.

Now with the new upgrade all my reverse proxy code is broken. It seems that the URL's returned are not relative anymore.Earlier i used to get subsequent URL's like
http://host/analytics/bundles/commons.style.css?v=9689 but now the relative URL is gone and I am getting
only http://host/bundles/commons.style.css?v=9689.

This is my nginx config on kibana machine link. Please let me know if there is any work around for me.I tried URL.basepath property but I am not sure why I am not able to make that work.


Kibana 5 behind reverse proxy
(Joe Fleming) #2

Have you added /analytics to the basePath in your kibana.yml file.

If so, it sounds like this happened when upgrading Kibana versions. What version where you running before when it worked, and what version are you trying to run now?


(Abhijitdeka11) #3

Yes I have added this in the Kibana.yml file. Yes, this happened because of the upgrade.I was on Kibana 4.1 and now upgraded to Kibana 4.4 .I can see this issue here and here but these are already closed. But i can still reproduce them at my end.How do I proceed?


(Joe Fleming) #4

Both of those issues target older versions of Kibana, and the fixes are definitely in 4.4.x. Part of our development process includes running Kibana behind a reverse proxy, which we do explicitly to make sure we don't break the basePath stuff again (we also use SSL for the same reason).

One cause I can think of is that either the setting in the yml is somehow wrong (misspelled or something perhaps), but this should cause Kibana to fatal on startup. The other thing that comes to mind is maybe the file isn't being used (perhaps it's in the wrong path or has the wrong permissions or something?).

Can you try changing another setting to ensure that it's being used? A good candidate would be to change the elasticsearch.url setting to something invalid, like using the wrong hostname and/or port. Then, restart Kibana and ensure that it fails to connect to your ES instance. Let me know if you can do that, and how it goes.


(Abhijitdeka11) #5

Ok this is what I did.
1.Downloaded and started ES2.2.0
2.Indexed a document
3. Downloaded the latest Kibana4.4.1 zip via the downloads page.
4.Extracted and started Kibana.
6.Go to http://localhost:5601 I can see the indexed doc in the discover tab after I configure the index.

All working fine for me till now.Now the next steps
6. Un-commented the entry and added
server.basepath:"analytics"

7.Restart kibana.
8.http://localhost:5601 redirects me to http://localhost:analytics/app/kibana and a 404 error throws up.
9.http://localhost:5601/app/kibana tries to load other resources from /analytics/bundles and hangs since it's not available.

What is the expected behavior here?Where should I see the kibana homepage now?
I think this is pretty easy to reproduce.


(Matt Bargar) #6

server.basepath should be set to /analytics, note the slash that's included. Your nginx config then needs to listen for requests to localhost/analytics and pass them to kibana without the /analytics


(Abhijitdeka11) #7

Thanks @Bargs . If it's not too much trouble for you can you please share your config file. A sample should help me.
I was trying to find an example but couldn't find one.


(Abhijitdeka11) #8

@Bargs I tried what you mentioned here. So, redirecting from /ananlytics to localhot:5601 is working fine for me.
The issue is with Kibana. As I mentioned localhost:5601 redirects me to localhost:5601/analytics/app/kibana and it's throwing 404 error.

Kibana running on 5601 is not accessible anymore.


(Matt Bargar) #9

I'm not sure I understand exactly.

Are you trying to access kibana directly?

Or are you saying that nginx is proxying from localhost:80/analytics to localhost:5601, and kibana is returning a redirect to nginx for localhost:5601/analytics/app/kibana?


(Joe Fleming) #10

http://localhost:5601 redirects me to http://localhost:analytics/app/kibana and a 404 error throws up

That's normal - when you set the basePath, Kibana will 301 all requests and re-write all asset URL paths to include your basePath prefix. You can no longer just hit localhost:5601, because Kibana doesn't actually this is expected. Once you specify a basePath, you need to actually observe that path, via your reverse proxy.

I did just set this up, and one catch here is that you won't be auto-redirected to /app/kibana from the proxy path (which seems like a bug, honestly). But, according to the nginx config you posted earlier, the following url should work, assuming you have running on the machine and running without ssl on port 5601: https://10.6.204.104/kibana4/app/kibana


(Abhijitdeka11) #11

@Bargs Sorry if I am not clear to you. I am trying to hit the URL from all sort of combinations. I think posting my configurations will make this more clear.
Here is my kibana.yml file configuration for base path

server.basePath: "/analytics"

Here is my corresponding nginx.config

Can you tell me is there anything wrong with my configuration?
I am trying to hit all sort of combinations in the URL.But nothing is working for me.


(Abhijitdeka11) #12

@Joe_Fleming I am trying to simplify my question. I want to see all kibana in /analytics path.
Here is my kibana.yml base path

server.basePath: "/analytics"

Here is my corresponding nginx.config

If I am understanding you correctly https://10.6.204.104/analytics/app/kibana should work.But it is still throwing
{"statusCode":404,"error":"Not Found"}

Is there anything wrong in my config file?
Not sure what is the expected URL i am supposed to hit. I tried all sorts of combinations.


(Yodog) #13

have you tried this?


(Deshymers) #14

Hello,

I was having the same issue as what was stated above, and I solved it with help from the following post. http://serverfault.com/questions/681238/kibana4-nginx-reverse-proxy-using-location-kibana4-not-found-404

This is my nginx snippet for Kibana,

location ~ ^/kibana/(.*)$ {
        rewrite /kibana/(.*) /$1 break;
        proxy_pass http://localhost:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

A single note on the above snippet, proxy_pass passes the entire path with the request, and we dont want to pass along the "/kibana" so we need to remove it with a rewrite! and that what is causing the 404.

I also had to set my basepath in kibana to "/kibana".


Kibana and Nginx in subpath
Nginx on ES/Kibana machine
(Abhijitdeka11) #15

Thanks Guys. I was able to solve it long back. The key was to consume the server.basepath url on your request.It should be documented somewhere properly.


(system) #16