Today we’ll see how to configure nginx as an instance on an EC2 instance.
But first, we need to know what nginx is.
*Nginx *(pronounced “engine-x”) is a popular open-source web server used for serving websites, applications, reverse proxying, load balancing, and more. Originally developed to solve concurrency problems with traditional web servers (like Apache), Nginx is now used by giants like Netflix, Airbnb, Dropbox, and WordPress.com for its speed, stability, and low resource consumption.
A load balancer is a system (hardware or software) that distributes incoming network traffic across multiple servers to improve efficiency, reliability, and performance.
To complete our task today, we need to create an EC2 instance and link it to an SSH client. For those who are confused, click here.
After Creating your first EC2 instance, you will have to create two more.
Note: we’ll use an EC2 with ubuntu as
Now let’s start.
First Step: Installing and configuring the application
After creating and connecting your instance, execute the following instruction:
- sudo su • Function: Switches to superuser (root) mode. • What does it do?: Gives full system authority (caution: risk of critical changes). Avoids having to type sudo before each command.
- apt-get update -y • Function: Updates the list of available packages from the Ubuntu/Debian repositories. • What does it do? -Synchronizes package information with remote servers. -Required before installing or updating software to avoid version errors. Explanation of options: • y: Automatically responds “yes” to any confirmations.
- apt-get install nginx -y • Function: Installs the Nginx server from the official repositories. • What is it for?- Installs a powerful web server (to host a site, an API, etc.).- Automatically starts the Nginx service after installation. Options explained: • y: Automatically confirms the installation.
- rm -rf /etc/nginx/sites-enabled/default • Function: Removes the default Nginx configuration file. • What is it for? -Disables the default site (“Welcome to Nginx” page). Avoids conflicts with a custom configuration. Options explained: -rf: Force deletion (-f) and include folders (-r).
- nano /etc/nginx/conf.d/eliab.conf Purpose: Opens the eliab.conf file in the Nano text editor. What does it do? -Creates/modifies a custom Nginx configuration (e.g., to host a specific site). Sample content for a website:
the server name represents the IP Public address of the instance where you install your nginx. the two servers represent the others.
second step: configure your other two ec2 instances
in the configuration of your ec2 instances, go to advanced details and enter:
After that, create your instance.
third step: configure your ec2 instance’s security group
Go to your ec2 instances and edit your inbound rules.
And now you have finished.
Top comments (0)