# Elasticsearch setup with nginx and nodejs

**URL:** <https://discuss.elastic.co/t/elasticsearch-setup-with-nginx-and-nodejs/50054>\
**Category:** Elasticsearch\
**Created:** [May 14, 2016, 7:15pm UTC](https://discuss.elastic.co/t/elasticsearch-setup-with-nginx-and-nodejs/50054 "2016-05-14T19:15:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiteshanand](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jiteshanand](https://discuss.elastic.co/u/jiteshanand)\
**Post date:** [May 14, 2016, 7:15pm UTC](https://discuss.elastic.co/t/elasticsearch-setup-with-nginx-and-nodejs/50054/1 "2016-05-14T19:15:12Z")

</div>

I am using nginx as web/proxy server for my website build using MEAN stack. So the configuration file for nginx looks like  
server {  
listen 80;  
server\_name [www.domainname.com](http://www.domainname.com);  
location / {  
proxy\_pass [http://localhost:3000](http://localhost:3000);  
proxy\_http\_version 1.1;  
proxy\_set\_header Upgrade $http\_upgrade;  
proxy\_set\_header Connection 'upgrade';  
proxy\_set\_header Host $host;  
proxy\_cache\_bypass $http\_upgrade;  
}

location /blog {  
proxy\_pass [http://localhost:2368](http://localhost:2368);  
proxy\_http\_version 1.1;  
proxy\_set\_header Upgrade $http\_upgrade;  
proxy\_set\_header Connection 'upgrade';  
proxy\_set\_header Host $host;  
proxy\_cache\_bypass $http\_upgrade;  
}  
}

Node server is running on port 3000 and my blog is running on 2368.This setup is running fine.  
Now I have included elasticsearch also in the same aws server which is listening to port 9200 and added the following code in nginx config file

server {  
listen 9200;  
server\_name [www.domainname.com](http://www.domainname.com);  
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://www.domainname.com:9200/;](http://www.domainname.com:9200/;)  
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;

}  
}

After adding this ..I am getting error

bind() to 0.0.0.0:9200 failed (98: Address already in use)

Can anyone help me in this.Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 17, 2016, 7:18pm UTC](https://discuss.elastic.co/t/elasticsearch-setup-with-nginx-and-nodejs/50054/2 "2016-05-17T19:18:35Z")

</div>

You can't have nginx and ES both listening on port 9200. I suggest you reconfigure ES to use some other port.

---

<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, 10:50pm UTC](https://discuss.elastic.co/t/elasticsearch-setup-with-nginx-and-nodejs/50054/3 "2017-07-05T22:50:52Z")

</div>


