Put Elasticsearch behind Apache

Hi guys,

Maybe my question is dumb but I have an issue. I work on a remote server and I started Elasticsearch on default port (9200). The problem is that this port is closed from the outside. We can't access Elasticsearch on my local computer for example. We also have Apache on this server. Is this possible to put a reverse proxy to access Elasticsearch through Apache web server (so port 80) ? I didn't find how to do that with Elasticsearch...

Any ideas ?

Thanks !

PS : Sorry for my English, I promise I do my best.

Welcome!

No worries with your English :wink:
If you prefer speaking French, there's this space: https://discuss.elastic.co/c/in-your-native-tongue/discussions-en-francais

Yes you can put a reverse proxy. But why not opening the port?

1 Like

Thanks David.

I can't open the port unfortunately... I tried this in my Apache configuration file :

<Location /elastic>
    ProxyPass http://localhost:9200/
    ProxyPassReverse http://localhost:9200/
</Location>

It works when I reach http://nameserver.com/elastic from my computer, but if I try more complicated requests, it doesn't.

Do you know what is wrong with my configuration on Apache ?

Why? I mean: what did you do exactly?
Did you change the elasticsearch configuration?

What does it mean? Any example of a request and the response?

No. I'm not using Apache myself.

1 Like

Because it's the server of my job and I can't open a port... or maybe I miss something...

Yes sure. If I try (from my computer)

curl http://servername.com/elastic

I got :

{
  "name": "goes-search1",
  "cluster_name": "goes-search",
  "cluster_uuid": "PSbPv26KSVaoZXbaV7JAQw",
  "version": {
    "number": "7.3.0",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "de777fa",
    "build_date": "2019-07-24T18:30:11.767338Z",
    "build_snapshot": false,
    "lucene_version": "8.1.0",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

But if I try (from my computer) :

curl -X GET "http://servername.com/elastic/_cat/indices/"

I got :

{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index []",
        "resource.type": "index_expression",
        "resource.id": "",
        "index_uuid": "_na_",
        "index": ""
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index []",
    "resource.type": "index_expression",
    "resource.id": "",
    "index_uuid": "_na_",
    "index": ""
  },
  "status": 404
}

But, if I make the same request on the server with the port, it works... (I have some indices)

Why not running Elasticsearch on port 80 then?

Anyway, I believe you need to do a correct path rewriting like this example for nginx:

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

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.