# Elastic Cloud Elasticsearch with nginx reverse proxy

**URL:** <https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152>\
**Category:** Elasticsearch\
**Created:** [February 12, 2021, 3:42pm UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152 "2021-02-12T15:42:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrystalDesignDR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/crystaldesigndr/32/114545_2.png) [@CrystalDesignDR](https://discuss.elastic.co/u/CrystalDesignDR)\
**Post date:** [February 12, 2021, 3:42pm UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/1 "2021-02-12T15:42:26Z")

</div>

Hi,  
I'm trying to use nginx to have a better looking domain name for elastic cloud,  
APM reverse proxy works so far, however the elasticsearch endpoint wont work, any ideas?

I've also tried everything listed here [Nginx proxy for Elastic Cloud instance - Elastic Stack / Elasticsearch - Discuss the Elastic Stack](https://discuss.elastic.co/t/nginx-proxy-for-elastic-cloud-instance/161360)

```auto
        location / {
          proxy_pass https://uuid.apm.westeurope.azure.elastic-cloud.com/;
          proxy_set_header X-Real-IP $remote_addr;
        }
        location /es/ {
          proxy_pass https://uuid.westeurope.azure.elastic-cloud.com:9243/;
          proxy_pass_request_headers on;
          proxy_set_header Host uuid.westeurope.azure.elastic-cloud.com:9243;
        }
        location /apm/ {
          proxy_pass https://uuid.apm.westeurope.azure.elastic-cloud.com/;
          proxy_set_header X-Real-IP $remote_addr;
        }

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 12, 2021, 4:18pm UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/2 "2021-02-12T16:18:23Z")

</div>

This is an excellent detailed article on how to do this by one of our engineers, I would highly recommend it.

> **[Custom Domains and Anonymous Access on Elastic Cloud](https://xeraa.net/blog/2020_custom-domains-and-anonymous-access-on-elastic-cloud/)**
>
> Workaround for two commonly requested features with the help of proxies

---

<div class="post-metadata">

**Author:** ![CrystalDesignDR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/crystaldesigndr/32/114545_2.png) [@CrystalDesignDR](https://discuss.elastic.co/u/CrystalDesignDR)\
**Post date:** [February 15, 2021, 8:14am UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/3 "2021-02-15T08:14:45Z")

</div>

Hi, thanks for your response, I actually went through this the other day, but no luck with this either.

```auto
#Neither this
        location /es/ {
          proxy_pass https://xxElasticsearchUUIDxxx.westeurope.azure.elastic-cloud.com:9243/;
          proxy_set_header X-Found-Cluster xxElasticsearchUUIDxxx;
        }

#nor this
        location /es/ {
          proxy_pass https://xxElasticsearchUUIDxxx.westeurope.azure.elastic-cloud.com:9243/;
          proxy_http_version 1.1;
          proxy_set_header Host xxElasticsearchUUIDxxx.westeurope.azure.elastic-cloud.com;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Connection "";
        }

```

#Nginx error log /var/log/nginx/error.log:

```auto
2021/02/15 08:01:40 [crit] 10965#0: *24 connect() to 20.50.174.29:9243 failed (13: Permission denied) while connecting to upstream, client: 20.82.106.29, server: my.customdomain.com, request: "GET /es/ HTTP/1.1", upstream: "https://20.50.174.29:9243/", host: "my.customdomain.com"

```

Running RHEL 7.9 with nginx/1.16.1 secured with Letsencrypt

Elastic Cloud on Azure WE

APM works as mentioned above, also briefly tried Kibana but wont work either (Kibana not important ATM though)

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 16, 2021, 1:09am UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/4 "2021-02-16T01:09:13Z")

</div>

Hi @CrystalDesignDR unfortunately my expertise does not lie in the reverse proxy space, I will poke around and see if anyone has a suggestion (no promises) perhaps @xeraa who wrote that article, might be able to comment. (no promises)

what does it look like if you just try to `curl` the elasticsearch endpoint what do you get?

One thing I did notice when I turned on the dev tools that that the headers from Kibana to Elasticsearch had the header defined as `x-found-handling-cluster` perhaps that header has changed.

---

<div class="post-metadata">

**Author:** ![CrystalDesignDR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/crystaldesigndr/32/114545_2.png) [@CrystalDesignDR](https://discuss.elastic.co/u/CrystalDesignDR)\
**Post date:** [February 16, 2021, 5:59am UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/5 "2021-02-16T05:59:31Z")

</div>

Hi @stephenb thanks again for your response,  
we figured it out, problem was with SELinux, it was set to enforcing. We turned it off and rebooted the server and now everything is working fine.  
Config file (RHEL/CENTOS)

```auto
 vi /etc/selinux/config

```

set to permissive or disabled

```auto
SELINUX=disabled

```

---

<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:** [March 16, 2021, 6:00am UTC](https://discuss.elastic.co/t/elastic-cloud-elasticsearch-with-nginx-reverse-proxy/264152/6 "2021-03-16T06:00:16Z")

</div>

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