DEV Community

Tikam Singh Alma
Tikam Singh Alma

Posted on • Edited on

How web server works in the cloud

What do you think is the first thing that happens when you hit some requests from your browser?

  • It goes somewhere to the internet? But where?
  • To the internet via DNS and networks, to the cloud?
  • But what is a cloud and what happens in the cloud?

Let’s learn the basics of how a web server works by using Apache2 as an example.

When an HTTP request arrives, the webserver starts processing and looking up the requested resources by the clients.

While the webserver processes the requests, the client might send another request. Those requests are either ignored or handled simultaneously by the webserver.

A web server that gets another follow-up or subsequent requests is ignored or queued because servers are busy processing initial requests. This process is called single-threaded web servers, this means they can handle one request at a time.

Web servers that can handle multiple requests, manage the servers in two ways, that is initial request and its follow-up requests are also handled. This is done by webservers, either web server starts a new processor starts a new thread within a process.

Webserver that works and manages multi processes are called multi-threaded webservers

IIS(Internet Information Service) on the windows platform is an example of a multi-threaded webserver.

Apache on the Unix platform is a multi-process web server.

Apache is a multi-threaded web server and it is based on a modular architecture.

Top level view components of apache webserver are:

  • The Apache Core
    • Which handles the basic functionality of the server. Such as allocating requests and maintaining and pooling all the connections
  • The Apache Modules:
    • Apache modules are the individual small components or plugins(extensions),

The Apache core provides the main functionality of an HTTP web server and modules are needed in order to extend the core functionality of apache.

Image description

Apache core components and it’s working:

  • http_protocol.c

These are the components that handle routing and communication. It knows the socket connections through which the client connects to the server. All the data are transferred through this component.

  • http_main.c

This is the component that is responsible for the startup of the server and contains the main server loop that waits for and accepts connections

  • http_request.c

This is the component that handles the flow of request processing, and control of the required modules also manages the error handling.

  • http_core.c

This is the base of all the functions and implementations

  • alloc.c

This is the component that is responsible for the allocation of resources and tracking.

  • http_config.c

This component provides functions for other utilities, including reading configurations files and managing the information from those files, and as support for virtual hosts.

Apache module request phases.

Apache Webserver is used to serve both static and dynamic web pages and contents.
And all those static and dynamic contents of the web applications and web pages are processed by the apache core and apache functional modules.
And due to its high customization and configurations.

Request Phase on Apache

The phases or the logic that the HTTP_REQUEST Module of
the Apache core controls are as follows:

  • URI to filename translation;
  • Check access based on host address, and other available information;
  • Get a user id from the HTTP request and validate it;
  • Authorize the user;
  • Determine the MIME type of the requested object (the content-type, the encoding, and the language);
  • Fix-ups (for example replace aliases by the actual path);
  • Send the actual data back to the client;
  • Log the request;

Apache modules and it's working

Due to the architecture of the Apache, modules do not know directly about each other.
The requests are directly not processed by the apache modules, sending the information from one module back to the core then back to another module until the request is completely handled and then it is sent back to the client

Modules since they do not know directly about each other must pass all information back to the core and then the core sends that information to another appropriate module through the use of the HTTP_REQUEST component of the Apache Core.

Apache has lots of modules and since it’s open-source you can also create your own modules and install them on your configuration.

Examples of some of the most popular Apache modules.

  1. Mod_security
  2. Mod_rewrite
  3. Mod_deflate
  4. Mod_cache
  5. Mod_proxy
  6. Mod_ssl

Top comments (0)