Deploy all the things!
http://frontendcapstone.com
Get repo onto AWS instance and connect through a persistant IP or domain name
deploy!
set up domain frontendcapstone.com w/ google domains (domains.google.com)
https://aws.amazon.com/ec2/getting-started/
set up security policy on AWS EC2
I started with everything open and then restricted to port 80 UDP/TCP traffic for incomming. I also openned ICMP traffic for pinging purposes as well as ssh port 22 for logging into server.
set up elastic IP so it will persist after reboot/termination. you have to associate it to the instance from the elastic IP tab
Linux/UNIX instance:
- AMI name: amzn2-ami-hvm-2.0.20210617.0-x86_64-gp2
ssh from local:
set permissions to pem file:
chmod 400 hr-nylon-eric.pem
ssh -i hr-nylon-eric.pem ec2-user@ec2-35-172-51-196.compute-1.amazonaws.com
Then navigate to and create folder for project:
- install git
git clone https://github.com/Idakka/Project-Atelier.git
sudo yum install git
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
This is a special Node build for AWS instances. Don't use standard Yum/apt install.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
nvm install node
. ~/.nvm/nvm.sh
node -e "console.log('Running Node.js ' + process.version)"
npm install -g npx
- AWS version of nginx:
sudo amazon-linux-extras install nginx1
sudo service nginx start
- message: Redirecting to /bin/systemctl start nginx.service
cat /etc/nginx/sites-available/default
- this didn't work and I had to go find the etc/nginx/nginx.conf file and edit it with nano:
sudo nano /etc/nginx/nginx.conf
server { listen 80; server_name tutorial; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:3000; } }
- Most of this config was filled out, Just needed to add the location block and change to port 1234 for our server
sudo service nginx restart
- npm start in project folder, need ed to install nodemon
npm install webpack
npm start
https://medium.com/hackernoon/tutorial-creating-and-managing-a-node-js-server-on-aws-part-2-5fbdea95f8a1#.mnlkymeti
npm i -g pm2
pm2 start tutorial/index.js
- To make sure that your PM2 restarts when your server restarts
pm2 startup
- you will be given a custom string similar to this but specific to your machine, copy that:
sudo env PATH=$PATH:/home/ec2-user/.nvm/versions/node/v16.4.0/bin /home/ec2-user/.nvm/versions/node/v16.4.0/lib/node_modules/pm2/bin/pm2 startup systemd -u ec2-user --hp /home/ec2-user
save config with everything running (no nginx at this point)
pm2 save
pm2 start nodemon server/server.js
That’s it! You can log out/in to SSH, even restart your server and it will continue to run on port 80.
- To list all processes use
pm2 ls
systemctl start nginx
systemctl enable nginx
having trouble restarting nginx on reboot,
sudo systemctl enable nginx
- is supposed to solve it. needed to start nginx/ make persistant and THEN redo the pm2 process above
I got the app deployed pretty quickly but had to troubleshoot making the node server and nginx reverse-proxy persist after reboot.