0% found this document useful (0 votes)
5 views10 pages

Ec 2

This document provides a step-by-step tutorial for installing and configuring Nginx on an EC2 instance using Ubuntu Server 16.04 LTS. It covers launching an EC2 instance, SSH access, updating packages, installing Nginx, verifying its operation, creating a simple website, and setting up a virtual host. The guide concludes with instructions on terminating the EC2 instance to avoid costs.

Uploaded by

Duddukuri Srikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Ec 2

This document provides a step-by-step tutorial for installing and configuring Nginx on an EC2 instance using Ubuntu Server 16.04 LTS. It covers launching an EC2 instance, SSH access, updating packages, installing Nginx, verifying its operation, creating a simple website, and setting up a virtual host. The guide concludes with instructions on terminating the EC2 instance to avoid costs.

Uploaded by

Duddukuri Srikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Install and configure

Nginx on EC2
Nginx (pronounced as “Engine-X”) is an open source
web server that is often used as reverse proxy or
HTTP cache. It is available for Linux for free.

In this tutorial we’ll install Nginx and set up a basic site.


What you’ll learn
● How to set up Nginx
● Some basic Nginx configuration

What you’ll need


● A computer running Ubuntu Server 16.04 LTS
● Some basic knowledge of command line use
● Basic Knowledge about aws instance

1. Launch an EC2 Instance


● Log in to AWS Console: Go to AWS Management
Console.
● Navigate to EC2: From the services menu, select
EC2.
● Launch a New Instance:
○ Click Launch Instance.
○ Choose an Amazon Machine Image (AMI): For
this tutorial, select Ubuntu Server or Amazon
Linux.
○ Choose an Instance Type: Select t2.micro
(eligible for free tier).
○ Configure Instance Details: For basic
deployment, you can leave the default settings.

1
○ Add Storage: Keep default settings unless you
need more storage.
○ Configure Security Group:
■ Add an inbound rule for HTTP (port 80) to
allow web traffic.
■ Add an inbound rule for SSH (port 22) to
allow SSH access.
○ Launch: Review and launch the instance.
○ Download Key Pair: Choose or create a key
pair and download the .pem file. You'll need it to
SSH into the instance.

2. SSH into the EC2 Instance


● Open Terminal (Linux/macOS) or PowerShell
(Windows).

Navigate to the directory where the .pem file is located


and run the following command to connect to your EC2
instance:

➡️ ssh -i /path/to/your-key.pem
ubuntu@your-ec2-public-ip

2
● Replace /path/to/your-key.pem with the path to
your key file and your-ec2-public-ip with the
public IP of your EC2 instance.

3. Update the Package Lists


Before installing Nginx, update the package lists to get the
latest versions of the software:

➡️ sudo apt update # For Ubuntu

4. Install Nginx
Install Nginx using the package manager:

➡️ sudo apt install nginx -y # For Ubuntu


5. Start and Enable Nginx
After installation, start the Nginx service and enable it to
start on boot:

➡️ sudo systemctl start nginx


➡️ sudo systemctl enable nginx
6. Check the Nginx Status

3
You can check if Nginx is running by using
the following command:

➡️ sudo systemctl status nginx

4
7. Verify Nginx is Working
● Open your web browser and go to your
EC2 instance's public IP. You should
see the default Nginx welcome page,
which confirms that Nginx is running.
● To get the public IP, go to the AWS
console, open your instance, and check
the Public IPv4 address.

If you see this page, you have successfully installed Nginx


on your web server.

8. Creating our own website


Default page is placed in /var/www/html/ location. You can
place your static pages here, or use virtual host and place it other
location.

5
Virtual host is a method of hosting multiple domain names on the
same server.
Let’s create simple HTML page in /var/www/tutorial/ (it can
be anything you want). Create index.html file in this location.

➡️ cd /var/www

➡️ sudo mkdir tutorial

➡️ cd tutorial

➡️ sudo "${EDITOR:-vi}" index.html

Paste the following to the index.html file:

6
Save this file. In next step we are going to set up virtual host to
make Nginx use pages from this location.

9. Setting up virtual host


To set up virtual host, we need to create file in
/etc/nginx/sites-enabled/ directory.
For this tutorial, we will make our site available on 80 port, which is
standard port. You can change it if you would like to do.

➡️ cd /etc/nginx/sites-enabled

➡️ sudo "${EDITOR:-vi}" tutorial

root is a directory where we have placed our .html file. index is


used to specify file available when visiting root directory of site.
server_name can be anything you want, because you aren’t pointing
it to any real domain by now.

7
10. Activating virtual host and testing
results
To make our site working, simply restart Nginx service.

Let’s check if everything works as it should. Open


our newly created site in web browser. Remember
that we used :80 port.

Congratulations! Everything works as it should. We


have just configured Nginx web server.

11. Terminate the EC2 Instance


(Optional)

8
If you no longer need the EC2 instance, remember
to terminate it to avoid incurring costs:

● Go to EC2 Dashboard.
● Select the instance and choose Actions > Instance
State > Terminate.

That's it! Nginx is now deployed on your EC2 instance and


serving web pages over the internet.

Thank you..!
🙏🏻 Author :- Sidhant bote

Mentor :- Ashutosh bhakare sir

You might also like