# How to connect Elasticsearch over HTTPS with Nginx as a reverse proxy server

**URL:** <https://discuss.elastic.co/t/how-to-connect-elasticsearch-over-https-with-nginx-as-a-reverse-proxy-server/76114>\
**Category:** Elasticsearch\
**Created:** [February 22, 2017, 9:42pm UTC](https://discuss.elastic.co/t/how-to-connect-elasticsearch-over-https-with-nginx-as-a-reverse-proxy-server/76114 "2017-02-22T21:42:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [February 22, 2017, 9:42pm UTC](https://discuss.elastic.co/t/how-to-connect-elasticsearch-over-https-with-nginx-as-a-reverse-proxy-server/76114/1 "2017-02-22T21:42:01Z")

</div>

I run Elasticsearch 5.0 on my production server.  
I use Nginx as a reverse proxy server.  
My website is secured with Let's Encrypt so I need Elasticsearch to run over `https` like this  
`curl -XGET https://172.31.18.5..........` otherwise my site fails to receive data from Elasticsearch.  
I've read [this post](https://www.ralphlepore.net/setting-up-basic-authentication-with-elasticsearch/) for setting up basic authentication for Elasticsearch with Nginx.  
The post suggests configuration as the below.

```
server {
    listen 80;
    server_name {{ your_search_domain }};
    rewrite ^ https://$server_name$request_uri? permanent;
}

server {
    listen 443;
    server_name {{ your_search_domain }};
    ssl on;
    ssl_certificate {{ ssl_dir }}/elasticsearch.crt;
    ssl_certificate_key {{ ssl_dir }}/elasticsearch.key;

   access_log {{ nginx_log_file }};
   error_log {{ nginx_error_file }};

    location / {
        rewrite ^/(.*) /$1 break;
        proxy_ignore_client_abort on;
        proxy_pass http://localhost:9200;
        proxy_redirect http://localhost:9200 http://{{ your_search_domain }}/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        auth_basic "Search Authentication";
        auth_basic_user_file {{ nginx_htcontrol }};
    }
}

```

I have changed the parts surrounded by {{ }} but failed to run it over `https`.  
It only accepts `http` like this `curl -XGET http://172.31.18.5...........`  
Can I use the same Let's Encrypt certificate and key for `ssl_certificate` and `ssl_certificate_key` respectively?  
Should `proxy_pass` be like `proxy_pass http://172.31.18.5:9200` ?

**My setups**  
I have only one master-eligible data node in my cluster.

I set `number_of_shards` to 1, and `number_of_replicas` to 0.

The followings are the setups for my `elasticsearch.yaml`.

```
http.cors.enabled: true
http.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/
cluster.name: MyAppName
node.name: ${HOSTNAME}
bootstrap.memory_lock: true
network.host: 172.31.18.5
discovery.zen.minimum_master_nodes: 1
```

---

<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 22, 2017, 9:43pm UTC](https://discuss.elastic.co/t/how-to-connect-elasticsearch-over-https-with-nginx-as-a-reverse-proxy-server/76114/2 "2017-03-22T21:43:00Z")

</div>

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