Skip to content

Instantly share code, notes, and snippets.

@airportyh
Last active February 1, 2017 02:56
Show Gist options
  • Select an option

  • Save airportyh/b0c9ee17fbcdc823f6a351d0e8c87178 to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/b0c9ee17fbcdc823f6a351d0e8c87178 to your computer and use it in GitHub Desktop.

Install Node.js on EC2 Ubuntu

  1. Clone source code for your project and put it under /var/www
  2. Install pm2 on your server: sudo npm install pm2 -g
  3. Enable proxy module for Apache: sudo a2enmod proxy_http
  4. Start your Node.js server program using pm2: pm2 start backend.js, now you can monitor your server processes via pm2 list
  5. Create an Apache site configuration .conf file under /etc/apache2/sites-available. Let say it's mysite.conf It should look something like:
<VirtualHost *:80>
        ServerName socket-chat.com

        Alias / /var/www/socket-chat/public
        <Directory /var/www/socket-chat/public/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyRequests on
        ProxyPass / http://localhost:3000/
</VirtualHost>

Then run sudo a2ensite mysite.

The parts you haven't seen is the Proxy stuff. The only thing you have to make sure is that ProxyPass goes to a URL of the correct port - the one your Node.js server is listening on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment