Nginx – Serve Elasticsearch and Kibana on the Same Host

elasticsearchkibananginxreverse-proxy

Totally new to nginx, I need a conf file to make nginx act as a reverse proxy to serve request on the same host to elasticsearch and kibana with different url path.
I mean, I want:

localhost/es -> localhost:9200
localhost/kibana -> localhost:5601

How can I make it?

Thank you

Best Answer

So, the complete answer is:

server {
    listen 80;
    server_name $hostname localhost;

    auth_basic "Restricted";
    auth_basic_user_file pathtofile;

    location /kibana {
        rewrite ^/kibana/(.*)$ /$1 break;
        proxy_pass http://localhost:5601/;
    }
    location ~ ^/es(.*) {
        rewrite /es/(.*) /$1  break;
        proxy_pass http://localhost:9200;
    }   
}

still, I don't know why, but Kibana first request is served very slowly (40secs). Tried with apache httpd and it's way much faster.

Related Topic