Hosting Your Node Application on Apache

Hosting Your Node Application on Apache

I have a couple of applications running on localhost:3000 that I have configured from the /etc/hosts file. This preserves the host name when the node server fires up.

$ sudo -i

# Enable Apache modules required to run your app:
$ a2enmod proxy proxy_http headers
$ service apache2 restart

# Create an /etc/hosts entry

# Create a vhost entry with this configuration:
    > <VirtualHost *:80>
    > ServerName [HOST NAME]
    > ServerAlias [HOST NAME]
    > DocumentRoot [LOCAL PATH]
    > ProxyRequests off

    > <Proxy *>
    > Order deny,allow
    > Allow from all
    > Require all granted
    > </Proxy>

    > <Location>
    > ProxyPass http://localhost:3000/
    > ProxyPassReverse http://localhost:3000/
    > </Location>

    > RequestHeader set Host "[HOST NAME]"
    > ProxyPreserveHost On
    > </VirtualHost>

# Enable (a2ensite) your site if you haven't done so
$ service apache2 restart


# Troubleshooting:
# When running nodemon, you get Error: watch ENOSPC:
$ echo fs.inotify.max_user_watches=524298 | sudo tee -a /etc/sysctl.conf && \
    sudo sysctl -p

# FATAL ERROR- JS Allocation failed - process out of memory:
$ node --max-old-space-size=2048 [NODEJS FILE].js