# Put Elasticsearch behind Apache

**URL:** <https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233>\
**Category:** Elasticsearch\
**Created:** [April 2, 2020, 2:39pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233 "2020-04-02T14:39:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bergy27](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Bergy27](https://discuss.elastic.co/u/Bergy27)\
**Post date:** [April 2, 2020, 2:39pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/1 "2020-04-02T14:39:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 2, 2020, 4:22pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/2 "2020-04-02T16:22:42Z")

</div>

Welcome!

No worries with your English 😉  
If you prefer speaking French, there's this space: [https://discuss.elastic.co/c/in-your-native-tongue/discussions-en-francais](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?

---

<div class="post-metadata">

**Author:** ![Bergy27](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Bergy27](https://discuss.elastic.co/u/Bergy27)\
**Post date:** [April 3, 2020, 7:43am UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/3 "2020-04-03T07:43:32Z")

</div>

Thanks David.

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

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

```

It works when I reach [http://nameserver.com/elastic](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 ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2020, 10:36am UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/4 "2020-04-03T10:36:09Z")

</div>

> [@Bergy27](#):
>
> I can't open the port unfortunately

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

> [@Bergy27](#):
>
> but if I try more complicated requests, it doesn't.

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

> [@Bergy27](#):
>
> Do you know what is wrong with my configuration on Apache ?

No. I'm not using Apache myself.

---

<div class="post-metadata">

**Author:** ![Bergy27](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Bergy27](https://discuss.elastic.co/u/Bergy27)\
**Post date:** [April 3, 2020, 1:03pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/5 "2020-04-03T13:03:29Z")

</div>

> [@dadoonet](#):
>
> Why? I mean: what did you do exactly?  
> Did you change the elasticsearch configuration?

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

> [@dadoonet](#):
>
> What does it mean? Any example of a request and the response?

Yes sure. If I try (from my computer)

```auto
curl http://servername.com/elastic

```

I got :

```auto
{
  "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) :

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

```

I got :

```auto
{
  "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)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2020, 1:33pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/6 "2020-04-03T13:33:04Z")

</div>

Why not running Elasticsearch on port 80 then?

Anyway, I believe you need to do a correct path rewriting like [this example for nginx](https://serverfault.com/questions/922504/nginx-serve-elasticsearch-and-kibana-on-the-same-host):

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 1, 2020, 1:33pm UTC](https://discuss.elastic.co/t/put-elasticsearch-behind-apache/226233/7 "2020-05-01T13:33:11Z")

</div>

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