A Journey to the Cloud: Using Ubuntu on AWS EC2 to install NGINX
Let’s continue this journey to the cloud! I’m learning new ways to efficiently utilize Amazon Web Services (AWS) for productivity and will continue to share them with you all. In my previous article, I displayed two different ways you could launch an Amazon EC2 instance to host a webpage. This article will be quite similar, except we’re using the open source operating system (OS), Ubuntu. Also, instead of installing Apache as I’ve done in my first article, I will show how to install another popular open source web server called NGINX.
You will need:
- An AWS IAM user account with permissions to access EC2
- AWS Key pair — I showed how to create one here
That’s it! Now, it’s time to get started.
Step 1: Login to AWS
- Login to your AWS IAM user account, confirm your region, and search EC2. Navigate to the left panel and click Instances.
- Once you’ve clicked on Instances, you will see an orange button labeled Launch Instances. Click the button and we will configure the instance to fit our needs.
Step 2: Create the EC2 instance
- Name the instance, choose the OS Ubuntu, and the free tier eligible instance type, t2.micro.
- The instance type may be chosen already, so make sure it is specifically t2.micro.
- Choose your key pair from the drop down menu or use the button to the right to create a new key pair, if you haven’t already.
- Next, comes the network settings. Click create security group, allow SSH traffic from My IP (your IP address will be listed), and allow HTTP traffic from the internet.
- We will keep the default storage settings.
- Go to advanced settings and scroll down to User Data.
- Copy the following command and paste into the user data box:
#!/bin/bash
#Install all available updates and nginx
apt-get update -y
apt-get install nginx -y
#Start nginx
systemctl enable nginx
systemctl start nginx
#Configure firewall to allow HTTP
ufw allow 'nginx http'
ufw enable
- Review the summary and confirm your settings. Click launch instance.
- You’ve successfully created an instance that has installed NGINX!
Step 3: Connect to the new EC2 instance
- Once the EC2 instance has been successfully launched, we’ll click connect to instance, click the tab EC2 Instance Connect, then copy the Public IP address of your instance.
- In your web browser, open a new tab, type http:// then paste your public IP address. For example:
http://3.83.201.236
- If you’ve followed all of the steps above, then you should receive a page similar to this:
We’re all done! Thank you for reading and following along! I hope this was helpful and I look forward to sharing more AWS projects as I continue to learn.