How to run nodejs with apache for ubuntu 12.04

Posted December 29, 2014 32k views

I’m trying to run an application in php with chat in nodejs and socket io
I follow this exemple
My application has the same architecture and it works well in localhost, but i have some problem to deploy my application in the server.
I’ve tried this solution
But I got a “503 Service Temporarily Unavailable” error,

My virtual host config is

<VirtualHost *:80>

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all

    <Location />

My client.js

$(document).ready(function() {
socket = io.connect('');

And server.js

var app = require('express').createServer()
var io = require('').listen(app);
blabla ...

Can you please help me to figureout what i’m doing wrong.
Thank you.

1 comment
  • Generally a 503 error would mean that apache was unable to reach the nodejs service on port 8080. I would ensure that nodejs is listening and it might be worth changing your ProxyPass and ProxyPassReverse entries to use the IP address instead of the domain name to see if that resolves the problem.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers

I finally fix it.
I change the location to my project path

<Location /path/of/my/project>

And to run node server.js in background i used Forever

install forever globally

npm install forever -g

Navigate to your Node.js application:

cd /path/to/your/node/app/

and run the server/main JavaScript file with forever:

forever start --spinSleepTime 10000 main.js

Where –spinSleepTime 10000 refers to the minimum uptime (in milliseconds) between launches of a crashing script. This command will work for almost all cases.


by Christian Fei
This is our tutorial on hosting multiple Node.js apps on a single VPS with nginx, forever, and crontab.

Hi @ryanpq,
Thanks for your response.
May be my question is stupid, but How can i ensure that nodejs is listening on port 8080 ?

telnet IP_HOST 8080
Trying IP_HOST...
telnet unable to connect to remote host: Connection refused
  • A “Connection refused” error means that there’s nothing glisten on port 8080. Is your node.js app running? Can you post the output of the following two commands?

    sudo netstat -plutn | grep node
    sudo ps wwaux | grep node
  • Hi kamaln7,
    sudo netstat -plutn | grep node
    I have no output for the fisrt command line.

    sudo ps wwaux | grep node
    Output => youssef 25064 0.0 0.1 9392 900 pts/0 S+ 17:07 0:00 grep –color=auto node

    The problem is I will manually run the node server.js to get the system works.
    I don’t understand how to run node server.js automatically

Use apache as a reverse proxy for nodejs, serves static files from apache directly.
Side note: IMHO apache is not the right front end for nodejs because it is not event base
I use nginx instead.
AFAIK the may not work behind apache, works perfectly on nginx
You will need an upgrade for http protocol somewehere and some extra header to tell node that it stays behind a reverse proxy.