Day 4 of 30 Learning AWS: Web Servers

Prajakta VadjePrajakta Vadje
6 min read

What is web server?

A web server is just like a delivery guy for the internet. when you visit a website web server finds a right files and sends them to your browser. So you can see and use the website Without a web server a website can not be shown to users.

How Web Servers Work

  1. You open a website in your browser .

  2. The browser sends a request to the web server (a computer running 24/7).

  3. The web server receives the request, finds the correct file (like index.html), and sends it back to your browser.

4. Your browser shows the webpage using that file.

  • You ask for a page.

  • Server finds it.

  • Send it back .

  • you see that page in your browser.

Why do we need Web Servers?

Server is just like a computer that never sleeps. it stores data, website or app and share with people whenever they ask

We Need Servers Because:

  • To show websites.

  • To manage and store data.

  • To run programs 24/7.

  • To many users at once, server handles millions of user request.

Why Web Servers Are Important In AWS?

AWS is all about running things on the cloud, and a web server is what makes a website or app live and accessible from anywhere in the world. In AWS when you launch a virtual machine called an EC2 instance you can turn it into a web server by installing web server software.

What if there no web server?

  • No websites can be served

  • No link between client and database

  • No request processing

Diagram: Web Server

Types of Web Servers Used in AWS

1. Apache HTTP Server

  • Apache is a web server software.

  • It helps you show websites on the internet.

When someone opens your website, Apache sends the web pages to their browser.

  • It's easy to use, even for beginners.

  • Works great with HTML, PHP, and WordPress.

  • It's free and open source.

  • Very commonly used in AWS EC2 Linux servers.

Steps to install apache(httpd) on Amazon linux:

  • sudo yum update httpd -y (update the apache server or system to the latest version)

  • sudo yum install httpd -y (here yum is the package manager, install is action and httpd is package)

  • httpd -v (to check httpd installed or not)

  • sudo service httpd start (start the httpd service)

  • sudo service httpd status (to check if httpd is running or not)

  • cd /var/www/html (This is the path to the folder where websites are stored by default on httpd web server in linux.)

  • sudo service httpd stop (to stop the service)

Steps to install apache on ubuntu

  • sudo apt update -y (apt is the package manager used on ubuntu)

  • sudo apt install apache2 -y (here apt is package manager, install is action, apache2 is package)

  • apache2 -v (to check version)

  • sudo service apache2 start (starts the service)

  • sudo service apache2 status (to check apache2 is running or not)

  • cd /var/www/html (This is the path to the folder where websites are stored by default on apache2 web server in ubuntu.)

  • sudo service apach2 stop (to stop the service)

  1. Nginx Server

Nginx is a web server a program that helps show websites to users. Just like Apache, Nginx is like a super fast waiter it takes in many orders and serves people quickly without slowing down.

  • It Delivers web pages to your browser when you visit a website

  • Can also act as a reverse proxy forwards requests to another server

  • Very fast and lightweight

  • Can handle many users at the same time

  • Great for high traffic websites

  • Often used with Node.js, React, or APIs

  • Can load balance and speed up web apps

Steps to install nginx on Amazon linux

  • sudo yum update -y

  • sudo yum install nginx -y

  • nginx -v

  • sudo service nginx start

  • sudo service nginx status

  • cd/ usr/share/nginx/html

  • sudo service nginx stop

Note: nginx folder path on amazon linux and ubuntu is different.

Steps to install nginx on Ubuntu

  • sudo apt update -y

  • sudo apt install nginx -y

  • nginx -v

  • sudo service nginx start

  • sudo service nginx status

  • cd /var/www/html

  • sudo service nginx stop

Let’s see an example of hosting a web page using a web server.

Suppose you have a running EC2 server in AWS. Now, you want to host a static web page on this server.
Even if you place the HTML files on the server, they won’t be visible to the public without a web server.

That’s because a web server (like Apache or Nginx) is needed to deliver those files to the browser when someone tries to visit your website.

In the above screenshot, we have not installed any web server.
So, our web page will not be published or delivered to the user. This is because there is no web server to find that page on the system or server and deliver it to the user. This is exactly where the web server comes in it helps locate the page and send it to the browser when someone visits your website.

Now, lets set up a static web page(html page) and serve it using the Nginx web server.

Step 1: Launch an EC2 Instance

Step 2: Connect to EC2

Step 3: Install Nginx

Step 4: Start Nginx

Step 5: Create Your HTML Page

Step 6: Test in Browser

Summary: Hosting a Static page with Nginx

created a static page using basic HTML and CSS to understand how Nginx works as a web server. Even though the web page was just simple code, it couldn't be seen by users until I set up Nginx. Nginx helped serve the webpage it found the HTML file on the server and delivered it to the browser when someone visited the site. This shows how important a web server like Nginx is even for the simplest website

Conclusion

A web server is an essential tool that allows users to access websites and applications through the internet. It takes the files (like HTML, CSS, images) from your server and delivers them to users’ browsers when they visit your site.

Importance of Web Servers

  • They host and serve web pages

  • Allow websites to be accessible 24/7

  • Help handle user requests and traffic

  • Enable communication between users and applications

  • Used in cloud platforms like AWS for scalable and flexible deployment

0
Subscribe to my newsletter

Read articles from Prajakta Vadje directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prajakta Vadje
Prajakta Vadje