top of page
  • Writer's pictureSuraj Dhakre

Setup NGINX Web Server on AWS EC2

Introduction: What is EC2 and Nginx?

Amazon Elastic Compute Cloud (EC2) is a web service provided by Amazon Web Services (AWS) that allows users to rent virtual servers in the cloud. With EC2, users can easily scale their computing resources up or down based on their needs, making it a flexible and cost-effective solution for hosting websites and applications. Nginx is a popular open-source web server and reverse proxy server that is known for its high performance and scalability. It is often used as a front-end server to handle incoming web requests and distribute them to backend servers. Nginx is lightweight and efficient, making it an ideal choice for serving static content and handling high traffic loads.


ec2 nginx


Setting up an EC2 instance on AWS

To set up an EC2 instance on AWS, follow these steps:


  1. Sign in to the AWS Management Console and navigate to the EC2 service.

  2. Click on "Launch Instance" to start the instance creation process.

  3. Choose an Amazon Machine Image (AMI) - Select Ubuntu Server 22.04 LTS (HVM), SSD Volume Type as AMI type 64-bit (x86) variant. I selected this instance type since it is free tier eligible.

  4. Choose an Instance Type - For the purpose of this tutorial, it suffices to use t2.micro instance. You can use instance from other family as well depending on your requirement.

  5. Configure Instance Details - Keep default settings for this step

  6. Add Storage - Keep default settings for this step

  7. Add tags - Keep default settings for this step

  8. Configure security groups Configure security groups as shown in the image below

ec2 nginx sg

In addition to security groups, you should also use key pairs to securely connect to your EC2 instance using SSH. A key pair consists of a public key that is stored on your instance and a private key that is securely stored on your local machine.

AWS key pair

Setting up Nginx on EC2

Once you have set up your EC2 instance, you can install Nginx on it to start serving your website. To install Nginx on your EC2 instance, follow these steps:


  1. Connect to your EC2 instance using SSH. You can use the private key file (.pem) that you downloaded when creating the key pair.

  2. Follow the guide here to setup nginx on your ec2.


Testing your website on Nginx

After running nginx on EC2 instance, you can test your nginx by accessing it in a web browser. To do this, follow these steps: 1. Open a web browser and enter your EC2 instance's public IP address or domain name in the address bar. 2. If everything is set up correctly, you should see your nginx homepage. If you encounter any issues, you can check the Nginx error logs for more information. The error logs are located in the /var/log/nginx/ directory.


Conclusion

Congratulations! You have successfully set up an EC2 instance on AWS and installed Nginx to serve your website.

Comments


bottom of page