logo

How To Host NodeJS Apps

Install Node by downloading from the official website.

Install forever:

$ npm install forever -g

Modify Apache config file: /etc/apache2/sites-available/000-default.conf(Ubuntu)

<VirtualHost *:80>
    ServerName app.example.com
    ProxyPreserveHost on
    ProxyPass / http://127.0.0.1:2368/
    ProxyPassReverse / http://127.0.0.1:2368/
</VirtualHost>

Make sure the port is correctly set. Now restart Apache server:

$ sudo apachectl restart
AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf:
Invalid command 'ProxyPreserveHost', perhaps misspelled or defined by a module not included in the server configuration
Action 'restart' failed.
The Apache error log may have more information.

if you see the above error message, enable proxy first:

$ sudo a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
  service apache2 restart

$ sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
  service apache2 restart

then restart again:

$ sudo apachectl restart

If you got 500 Internal Server Error, make sure proxy_http is enabled

$ ls /etc/apache2/mods-enabled/