Simple angular website deployment on Amazan EC2 instance
-
Hosts (/etc/hosts)
-
Virtual Hosts
-
Ports
-
Static sites/Dynamic sites
-
ssh/scp/rsynch
-
Launch instance t2.micro freetier
-
Download key from AWS console and save it to
~/.ssh
folder and then give below permission [You can download key only once ]chmod 400 ~/.ssh/demo.pem
-
Set Inboud Rules: Add
HTTP
Port80
source custom
-
ng new demo
-
ng serve
to test demo app -
ng build --prod
-
scp: Same syntax like copy:
scp -i ~/.ssh/demo.pem dist.zip ubuntu@ec2-52-66-7-24.ap-south-1.compute.amazonaws.com:/home/ubuntu
-
rsync:
rsync -Pav -e "ssh -i ~/.ssh/demo.pem" dist/ ubuntu@ec2-52-66-7-24.ap-south-1.compute.amazonaws.com:/home/ubuntu/dist
-
sftp:
sftp -i ~/.ssh/demo.pem ubuntu@ec2-52-66-7-24.ap-south-1.compute.amazonaws.com
get
andput
lls
,lcd
etc as per need
-
Nginx installation
sudo apt install nginx -y
a. Go to nginx site configuration
cd /etc/nginx/sites-available/
b. Backup Default config file
sudo cp default default.bk
c. Setup config in
sudo vim default
file, set root/var/www/html/dist/demo
and fallback configtry_files $uri $uri/ /index.html;
d. Restart server
sudo service nginx restart
-
Apache2 installation
sudo apt install apache2 -y
a. Go to apache site configuration
cd /etc/apach2/site-available
b. Backup default config file
sudo cp 000-default.conf 000-default.conf.bk
c. Setup config in
sudo vim 000-default.conf
file, setDocumentRoot /var/www/html/dist/demo
d. Add
.htaccess
at roote. Restart the server
sudo service apache2 restart
-
Jenkins/Codepipeline/Codestar/Teamcity etc
-
Git clone and create build
-
Copy deliverable directly using
scp
,sftp
,rsync
etca. Create zip of dist folder
zip -r dist.zip dist/
b. Copy zip to destinsation server using
scp -i ~/.ssh/key.pem dist.zip server URL:/home/ubuntu
c. Install unzip on deplotyment server
sudo apt install unzip
d. Unzip to desired directory
sudo unzip /home/ubuntu/dist.zip -d /var/www/html/
e. Restart web server
Hosting website on S3:
-
Must have readonly access to public
-
<bucket-name>.s3-website.<AWS-region>.amazonaws.com
-
ARN: Amazon Resource name
-
Sample permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::deployment-demo-ganesh/*"
}]
}
Hosting website on Github
-
Create the build with below command:
ng build --prod --output-path docs --base-href /simple-website-deployment-on-ec2/
-
Copy docs/index.html and name it docs/404.html
-
Commit docs directory and push it.
-
On the GitHub project page, configure it to publish from the docs folder
-
Under your repository name, click Settings, Use the Select source drop-down menu to select master as your GitHub Pages publishing source.