Intended to be a configuration to deploy easily from github into AWS EC2 instances
- Create a AWS EC2 Instance. For the purpose of running the project it can be a
t1.micro
instance runningubuntu
- Create the SSH keys and store them in a secure please
- Depending on the project the Ports allowed should be properly configured in the Security Groups sections. In the case of this project we're enabling ports 80 (HTTP) and 443 (HTTPS)..
- Configure an Elastic IP Address.
- Access the Created instance through SSH using the keys created in the previous section.
- Open the SSH Client
- Make sure to
chmod 400 key.pem
- Connect to the instance running
ssh -i "key.pem" ubuntu@<host>.compute.amazonaws.com
- Install Ngnin
- Once on the server type
sudo apt update sudo apt install nginx
- Allow incoming http and https connections
sudo ufw allow 'Nginx Full
- Check the status of the server
systemctl status nginx
- Configure ngnix to forward the connections from port 80 to port 3000
- Create a new configuration file for ngnix using
sudo nano /etc/nginx/sites-available/my-app
- Paste the configuration file content of this project called
nginx.config
- Create a symlink into sites-enabled directory
sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled
- Restart nginx
sudo systemctl restart nginx
- Create a new configuration file for ngnix using
- Setup project in ngnix server
sudo mkdir /var/www/my-app
and give permissionssudo chown www-data:www-data /var/www/my-app
sudo chmod -R 775 /var/www
and add to the correct groupsudo usermod -a -G www-data [my username]
- Install Node and pm2
Download nvm curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bashnv
source ~/.profile
- Install proper version
nvm install 14
- Install
pm2 globally npm install pm2 -g
- Deploy github actions.
- Add the SSH private key into the Github secrets. This file will be used in the following steps to open the connection from Github to AWS.
- Add the deploy.yml file the proper configurations. The file should be located at
.github/workflows
- Run pm2 in watch mode in the server
pm2 start /var/www/my-app/dist/index.js start --watch
The prefered package manager is yarn. Install it npm i -g yarn
Run yarn install
In the command line type yarn start