How to deploy to Amazon AWS (EC2)
First you need to have a custom domain name bought (can be bought in AWS)
Go to Route 53 click in hosted zones, created hosted zone and add your custom domain with type Public Hosted Zone. OBS: You may need confirm the domain you using. AWS sends an email to address of the domain owner.
- Click on your domain name and you will see the NS Register. Go to your domain register provider and configure the Name Servers (NS) with these on Hosted Zone.
Go to AWS Certificate Manager click o request a new Certificate
In the field domain name, create a wildcard .yourdomain.com and click review and request.
Amazon will send a confirmation email to the email linked to the domain, click on link to confirm this domain belongs to you.
Go to Amazon EC2 in the left bar under Network & Security click on Keypairs.
- Click on create, name your keypair and will be downloaded automatically. SAVE IT IN A SECURE PLACE OR YOU WILL NOT BE ABLE TO ACCESS THIS MACHINE AGAIN!!
Click on instances, launch instances, select ubuntu server 16.04 LTS, Select The instance type you desire and launch.
When it's online, select your created instance and, if you don't select a security group, there's created a new one.
Click on this name and you will be in Security Groups List (There's a link in left panel).
Go to Inbound tab, click on edit and Add Rule for your Port Http (80) and Https (443).
Go to Load Balancers (Left Bar) and create a new Load Balancer, selecting Application Load Balancer and click in next.
In Basic Configuration, name-it default (or anyway you like) and in listeners, add listeners to the ports 80 and 443.
Select Desired Availability Zones inside your VPC and click next
(Step 2) In Certificate Type, choose an existing certificate then we created in step 3. Click Next.
(Step 3) Select the same Security group then you're using in your EC2 Instance.
(Step 4) Select new Target Group, name it as default (or anyway you like), keep protocol http and port 80 in target group.´
(Step 4) In health checks select protocol http and put a path to health status. (The AWS will ping this url to check if the server is alive)
Select the machines you want to put under this load balance (We created just one for this example) and create.
Back Route 53 and enter in your hosted zone (domain)
Click on create record set, name it bot, type cname and check "alias" to yes
In target name, find your load balance.
Let policy simple and Evaluate Target Health No. Click Create
Remember of .pem file of step 4? Find his directory and filename and put in YOUR_KEY_DIRECTORY
Connect on your machine by ssh
ssh YOUR_KEY_DIRECTORY ubuntu@YOUR_AMAZON_AWS_PUBLIC_DNS
Obs: Go to EC2 -> Instances -> Select your instance and See "Public DNS (IPV4)"
3.If you use windows Git Bash (Distributed with Git for Windows) it's an excellent choice.
Now you connected, run this commands
cd ~ curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh sudo bash nodesource_setup.sh
Then install NodeJs and NPM with
sudo apt-get install nodejs
Next you need to compile some source files
sudo apt-get install build-essential
You can run
npm --version
andnode --version
to check if installation is ok.
Install pm2 to manage process
npm install -g pm2
Clone your project inside some server folder (i like to put into /var/app/myapp)
Go to your app folder and run
npm install
Put your app into production!
pm2 start npm -- start
that's all folks!