Nazar
Nazar

Reputation: 1799

SailsJS on production - Error: listen EADDRINUSE

I have a VPS server with CentOS and Apache server.

But I want to run my node.js applications too. I am using sails.js This sails application is trying to listen to port 80 of specified host.

Here is error (after sails lift running):

debug: Starting server in /var/www/user/data/nodeprojects/projectname...  
info  - socket.io started
debug: Restricting access to host: projectname.com  
warn  - error raised: Error: listen EADDRINUSE
warn:   
warn: Server doesn't seem to be starting.  
warn: Perhaps something else is already running on port 80 with hostname projectname.com?

What is the problem? Can I run both apache and nodejs servers on one server with one port (80)?

Upvotes: 1

Views: 1161

Answers (2)

Wreeecks
Wreeecks

Reputation: 2274

you cannot use same port for different application. NodeJS can use any open port. What you need todo is port forwarding for your app. :)

Upvotes: 0

Rob Raisch
Rob Raisch

Reputation: 17357

No, you cannot.

When a server process opens a TCP port to answer requests, it has exclusive use of that port. So, you cannot run both SailsJS and Apache servers on the same port.

Having said that, you can do lots of interesting things with Apache, such as proxying specific requests to other servers running on different ports.

A typical setup would have Apache on port 80 and SailsJS on port 8000 (or some other available port) where Apache would forward requests to certain URLs to SailsJS and then forward the reply from SailsJS back to the browser.

See either configuring Apache on Mountain Lion proxying to Node.js or http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache for example implementations of this approach.

Upvotes: 3

Related Questions