Deploying this blog to an AWS EC2 instance

created:

updated:

tags: web aws deployment

1. Launch an EC2 instance on AWS

  • Sign up on AWS
  • Launch an EC2 instance with a free-tier option
    • Ubuntu
    • Security Group
    • t2.micro
    • Download a key-pair for accessing the EC2 instance (ex: .pem file)
  • SSH into the EC2 instance
    • ssh -i <path_to_keypair_pem_file> ubuntu@<ec2_public_ip_address>
  • Install nginx for web server
  • Install other necessary packages such as git

2. Move the static files of the website onto EC2 instance

Ideally, when I have more knowledge on this, I’d like to automate the process of having the static files of the blog website through CI/CD pipeline such as GitHub Action.

  • Use scp to move directory and files to the EC2 instance
    • scp -i <path_to_keypair_pem_file> -r <your_local_files_and_directories> ubuntu@<ec2_public_ip_address>:<destination_path_to_move_files_to>
  • GitHub Action:
    • (to do in the future)

3. Move static files to /var/www/html

  • This blog website is made from Hugo so I used hugo build command to build its static files first. Then, I moved the public directory to the EC2 instance.
    • Ensure the index.html is there

4. Start NGINX server

  • sudo systemctl start nginx.service to start the NGINX server
  • sudo systemctl status nginx to check the status of the NGINX server
  • For me, I had to add sudo at the front of the command so that the EC2 instance does not ask me authentication password.

5. Access the static website through EC2 public IP address

  • We can open the web browser and access the public IP address, the static website is there!

Questions

  • How does NGINX work as a webserver?
  • The browser says “Not secure” for the IP address. How can I make it “Secure”?
  • How can I automate the building the static website and deploying to the EC2 instance?
  • NGINX serves as a proxy, load balancer, security (encryption), how can apply this to the EC2 instance?
  • How does ssh work?

References