# Js client could not connect to elasticsearch behind nginx

**URL:** <https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210>\
**Category:** Elasticsearch\
**Created:** [October 29, 2015, 6:15am UTC](https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210 "2015-10-29T06:15:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devaraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/devaraj/32/34573_2.png) [@devaraj](https://discuss.elastic.co/u/devaraj)\
**Post date:** [October 29, 2015, 6:15am UTC](https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210/1 "2015-10-29T06:15:29Z")

</div>

Hi,  
I am using nginx to protect the elasticsearch. When trying to access elasticsearch in client js. Its throwing Unable to revive connection: http://ubuntulocal:80:9200/ error.

My question is how to connect the elasticsearch using client js behind the nginx proxy ?

node js code

var elasticsearch = require('elasticsearch');  
var host = [  
{  
host: '[http://ubunutlocal:80](http://ubunutlocal:80)',  
auth: 'root:root'  
}]

var client = new elasticsearch.Client({  
host: host  
});

client.search({  
index : 'bank'  
// undocumented params are appended to the query string  
//hello: "elasticsearch"  
}, function (error , response) {  
if (error) {  
console.error('elasticsearch cluster is down!' , error);  
} else {  
console.log('All is well' , response);  
}  
});

Error log

Elasticsearch ERROR: 2015-10-26T13:14:06Z  
Error: Request error, retrying -- getaddrinfo ENOTFOUND ubuntulocal:80  
at Log.error (/node\_modules/elasticsearch/src/lib/log.js:213:60)  
at checkRespForFailure (/node\_modules/elasticsearch/src/lib/transport.js:192:18)  
at HttpConnector. (  
/node\_modules/elasticsearch/src/lib/connectors/http.js:153:7)  
at ClientRequest.wrapper (  
node\_modules/elasticsearch/node\_modules/lodash/index.js:3111:19)  
at ClientRequest.emit (events.js:107:17)  
at Socket.socketErrorListener (\_http\_client.js:271:9)  
at Socket.emit (events.js:107:17)  
at net.js:950:16  
at process.\_tickCallback (node.js:355:11)

Elasticsearch WARNING: 2015-10-26T13:14:06Z  
Unable to revive connection: http://ubuntulocal:80:9200/

Elasticsearch WARNING: 2015-10-26T13:14:06Z  
No living connections

elasticsearch cluster is down! { [Error: No Living connections] message: 'No Living connections' }

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 29, 2015, 6:23am UTC](https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210/2 "2015-10-29T06:23:41Z")

</div>

> [@devaraj](#):
>
> Unable to revive connection: http://ubuntulocal:80:9200/ error.

That doesn't look like a valid URL.

Are you proxying from 9200 to 80?

---

<div class="post-metadata">

**Author:** ![devaraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/devaraj/32/34573_2.png) [@devaraj](https://discuss.elastic.co/u/devaraj)\
**Post date:** [October 29, 2015, 6:25am UTC](https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210/3 "2015-10-29T06:25:40Z")

</div>

Yes I'm using nginx proxy and trying to connect to host: '[http://ubunutlocal:80](http://ubunutlocal:80)', url only

Nginx configuration

server {  
listen 80;  
server\_name guidanzlocal;  
location / {  
rewrite ^/(.\*) /$1 break;  
proxy\_ignore\_client\_abort on;  
proxy\_pass [http://localhost:9200](http://localhost:9200);  
proxy\_redirect [http://localhost:9200](http://localhost:9200) [http://guidanzlocal/;](http://guidanzlocal/;)  
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 "Elasticsearch Authentication";  
auth\_basic\_user\_file /etc/elasticsearch/user.pwd;  
}  
}

---

<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:** [July 5, 2017, 11:41pm UTC](https://discuss.elastic.co/t/js-client-could-not-connect-to-elasticsearch-behind-nginx/33210/4 "2017-07-05T23:41:56Z")

</div>


