Ec 2
Ec 2
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.
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.
➡️ 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.
4. Install Nginx
Install Nginx using the package manager:
3
You can check if Nginx is running by using
the following command:
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.
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
➡️ cd tutorial
6
Save this file. In next step we are going to set up virtual host to
make Nginx use pages from this location.
➡️ cd /etc/nginx/sites-enabled
7
10. Activating virtual host and testing
results
To make our site working, simply restart Nginx service.
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.
Thank you..!
🙏🏻 Author :- Sidhant bote