Deploying a Node.js/Express application on an Ubuntu 20.04 EC2 instance with Apache
- Follow steps 1-6 of the deploying a Django app to AWS guide
- Create an elastic IP address and associate it with your ec2 instance
- Install pm2 on the AWS instance with
npm i -g pm2
- Run
pm2 startup
and run the command it gives you - Run your application persistently with
pm2 start yarn -- start
- At this point you can now manage running processes with pm2 start/stop {processId}
- Install apache2 with
sudo apt-get install apache2
- Run these commands:
sudo a2enmod proxy
sudo a2enmod proxy_http
- 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>
- Run
sudo systemctl reload apache2
When you access your instance’s public domain you should now be able to see your application running!