Default template

How to deploy a Node app to AWS

By rimazk.

Last edited by ericlau. Created .

Deploying a Node.js/Express application on an Ubuntu 20.04 EC2 instance with Apache

  1. Follow steps 1-6 of the deploying a Django app to AWS guide
  2. Create an elastic IP address and associate it with your ec2 instance
  3. Install pm2 on the AWS instance with npm i -g pm2
  4. Run pm2 startup and run the command it gives you
  5. Run your application persistently with pm2 start yarn -- start
  1. At this point you can now manage running processes with pm2 start/stop {processId}
  1. Install apache2 with sudo apt-get install apache2
  2. Run these commands:
  1. sudo a2enmod proxy
  2. sudo a2enmod proxy_http
  1. Open /etc/apache2/sites-available/000-default.conf in your terminal-based editor of choice and make it look like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot <your-folder>

        <Directory />
        Options -Indexes +FollowSymlinks
        AllowOverride None
        Require all granted
        </Directory>

       ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia Full
        <Proxy *>
        Require all granted
        </Proxy>

        <Location />
            ProxyPass http://127.0.0.1:<port>/
            ProxyPassReverse http://127.0.0.1:<port>/
        </Location>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

  1. Run sudo systemctl reload apache2

When you access your instance’s public domain you should now be able to see your application running!