Js client could not connect to elasticsearch behind nginx

(devaraj) #1

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',
auth: 'root:root'

var client = new elasticsearch.Client({
host: host

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. (
at ClientRequest.wrapper (
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' }

(Mark Walkom) #2

That doesn't look like a valid URL.

Are you proxying from 9200 to 80?

(devaraj) #3

Yes I'm using nginx proxy and trying to connect to host: '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;
proxy_redirect http://localhost:9200 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;

(system) #4