How Web Servers Work?

 What is a Web Server? 


A web server is a software that listens for incoming connections and then utilizes the HTTP(S) protocol to deliver web content to its clients. 


The most common web server software is Apache, Nginx, IIS and NodeJS.


A Web server delivers files from what is called its root directory, which is defined in the software settings. 


For example: 


-------------------------------------------


Nginx and Apache share the same default location of 

/var/www/html 


In Linux operating systems.


-------------------------------------------


and IIS uses 

C:\inetpub\wwwroot


In Windows operating systems.


-------------------------------------------


For example: 


If a user requested the file => http://www.example.com/picture.jpg


It would send the file => /var/www/html/picture.jpg From its local hard drive. 


---------------------------------------------------------------------------------------------------------------------------------

Virtual Hosts


Web servers can host multiple websites with different domain names, to acheive this, they use virtual hosts. 


The web server software checks the hostname being requested from the HTTP(S) headers and matches that against its virtual hosts.


Virtual hosts are just text-based configuration files.


If it finds a match, the correct website will be provided. 


If no match is found, the default website will be provided instead. 


Virtual Hosts can have their root directory mapped to different locations on the hard drive. 


For example:


- one.com being mapped to /var/www/website_one


- and two.com being mapped to /var/www/website_two


There is no limit to the number of different websites you can host on a web server.

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Static VS Dynamic Content

---------------------------------

Static content, as the name suggests, is content that never changes. Common examples of this are pictures, javascript, CSS, ... etc (It can also include HTML that never changes.)


Furthermore, these are files that are directly served from the webserver with no changed made to them. 

---------------------------------

Dynamic content, on the other hand, is content that could change with different requests. 


for example: A blog. On the homepage of the blog, it will show you the latest entries. If a new entry is created, the home page is then updated with the latest entry.


Second example: A search page on a blog. Depending on what word the user make a search, different results will be displayed (google ... etc).


* This is all done with what is called the Backend, with the use of programming and scripting languages. 


* It is called the Backend because what is being done, is all done behind the scenes.


* The user cannot view the websites' HTML source and see what is happening in the Backend, while the HTML is the result of the processing from the Backend. Everything a user see in their browser is called the Frontend. 

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Scripting and Backend Languages


There is not much of a limit to what a backend language can achieve, and these are what make a website interactive to the user. 


Examples of these languages: PHP, Python, Ruby, NodeJS, Perl. 


- These languages can interact with databases, call external services, process data from the user, and so much more. 


A very basic PHP example of this would be if you requested the website: 

------------------------------------

http://example.com/index.php?name=adam

------------------------------------

If index.php was built like this:


<html><body>Hello <?php echo $_GET["name"]; ?></body></html>

------------------------------------

It would output the following to the client:


<html><body>Hello adam</body></html>

------------------------------------

PHP: A scripting language mostly used for web development.

------------------------------------


-----------------------------------------------------------------------------------------------------------------------------
Thank you for reading! 🙂

Roger

Comments

Popular posts from this blog

Common Network Commands: Ping

Common Network Commands: Route

John The Ripper