NGINX
AWS EC2
Linux 2
Installation Guide
Cloud Computing

How to install NGINX on AWS EC2 Linux 2

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

NGINX is a powerful, high-performance HTTP server and reverse proxy that is widely used for serving static files, load balancing, and other web server duties. Amazon EC2 instances running Linux 2 are a popular choice for hosting web applications on AWS and installing NGINX on them is a straightforward process. This article provides a step-by-step guide on how to install NGINX on an Amazon EC2 instance running Amazon Linux 2. We will also cover the basic configuration needed to get you started.

Prerequisites

Before you begin, ensure that you have the following:

  • An active AWS account.
  • Access to the AWS Management Console.
  • Basic knowledge of Linux command-line operations.
  • An EC2 instance running Amazon Linux 2. Ensure that you have SSH access to this instance.

Step-by-Step Guide to Installing NGINX

Step 1: Launch an EC2 Instance

  1. Navigate to the AWS Management Console and login with your credentials.
  2. Head to the EC2 Dashboard. Select "Launch Instance."
  3. Choose "Amazon Linux 2 AMI" as your image choice.
  4. Select an instance type. The "t2.micro" instance is suitable for testing and is often covered under the free tier.
  5. Configure security settings. Make sure to add an inbound rule that allows HTTP traffic on port 80.

Step 2: Connect to Your EC2 Instance

Once your instance is running, you can connect to it via SSH. Use the following command from your local machine:

  • Modify the server block: The default server configuration is found in /etc/nginx/nginx.conf or /etc/nginx/conf.d/ . Modify these files to set up your server blocks.
  • Set up reverse proxy: Modify the location block in the server configuration file to act as a reverse proxy. An example configuration might look like this:
  • Reload NGINX after changes:
  • Firewall issues: Ensure that your security groups allow inbound traffic on HTTP (port 80) and, optionally, HTTPS (port 443) if you're planning to use SSL.
  • Checking logs: If something goes wrong, inspect the log files located at /var/log/nginx/ . The access.log and error.log files can provide valuable insights.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.