Cloud & DevOps / 3 min read
AWS SERIES | NGINX | PART III
Introduction to AWS Series
AWS SERIES | NGINX | PART III

Introduction to AWS Series
Learning a new technology can be challenging, so I’m creating this AWS series to help people dedicate just 10 minutes a day to learning something valuable. Over time, these small lessons will add up to a fully-fledged skill set.
Note: We’ll mostly rely on free resources for this series.
Recap
In the previous article, we covered how to ssh into EC2 instance. Today, we’ll go over how to use nginx on AWS EC2 machine.
Tip: If you haven’t read the previous article, I recommend reviewing it first to follow along more easily.
Introduction to Nginx
Nginx is a powerful open-source software platform that provides various web server functions, primarily acting as a reverse proxy server. It is highly performant, scalable, and resource-efficient.
Functions of Nginx
- Web Server: Nginx can serve static files and is optimized to handle many simultaneous connections, making it ideal for high-traffic websites.
- Reverse Proxy: Nginx sits in front of an application server, forwarding client requests to the appropriate backend server.
- Load Balancer: It can also act as a load balancer, caching server responses and providing SSL/TLS encryption.
How to install Nginx on EC2 machine
- Create an EC2 Instance: Refer to the previous article if you need help creating an EC2 instance.
- Connect to the EC2 Instance: Once you have an EC2 instance, SSH into it using the AWS console by going to your EC2 instance > selecting it > clicking on “Connect” > choosing “EC2 Instance Connect” > and clicking “Connect.”
- Run Commands:
- Log in as a root user:
sudo -i- Update dependencies:
apt-get update- Check if Nginx is already installed and verify the Nginx configuration:
nginx -t- Install Nginx:
apt-get install nginx- Check Nginx status:
nginx statusOnce you run the Nginx status command, you should see Nginx in an active state. You’ve successfully installed Nginx on your machine.
How Nginx Acts as a Web Server
If someone visits http://your-server-ip, Nginx will look for an index.html file in the root directory (usually /var/www/html/) and send it to the user's browser.
To see the current content on your machine:
- Navigate to
/var/www/html/:
cd /var/www/html/2. List files in the current directory:
ls3. Run localhost:
curl localhost4. This command displays the default HTML file. If you want Nginx to serve a custom HTML file, create one with the following command:
echo "Welcome to AWS SERIES - PART III" > index.htmlNow, if you run curl localhost, it will display "Welcome to AWS SERIES - PART III".
Summary
This article provided a step-by-step guide on setting up and using Nginx on an AWS EC2 instance. We covered connecting to an EC2 instance, installing and configuring Nginx, and setting it up to serve a basic HTML file as a web server.
Queries and Doubts
Thanks for the read :) Hope you have enjoyed reading it 🤩 and learnt something new today.
If you have any doubts or queries feel free to drop a comment or
⁍ Connect with me on my 🔗Topmate 💬.
⁍ You can also reach out to me on my 🔗LinkedIn.
⁍ Please clap for this post if you enjoyed reading it 📗 and follow for more interesting articles.
⁍ You can also support me and my writings by treating me to a nice virtual cup of coffee ☕️.