Blog

What is: Web server – Apache vs Nginx

If you are new to IT world, you must wonder the term “web server”, what it means, how it works and how can it help you understand the Server Term. 

Let me try to justify on some of your doubts

What is web server : Apache vs NGINX

A web server is server software, or hardware dedicated to running said software, that can satisfy World Wide Web client requests. A web server can contain one or more websites. A web server processes incoming network requests over HTTP and/or HTTPS and several other related protocols.

The primary function of a web server is to store, process and deliver web pages to clients. 

How does web server understand your requests?

Web servers are able to map the path component of a Uniform Resource Locator (URL) into:

  • A local file system resource (for static requests)
  • An internal or external program name (for dynamic requests) (PHP files for php routing, nodejs requests to another port)

For a static request the URL path specified by the client is relative to the web server’s root directory.

Consider the following URL as it would be requested by a client over HTTP:

http://www.example.com/path/file.html

The client’s user agent will translate it into a connection to www.example.com with the following HTTP/2 request:

GET /path/file.html HTTP/2

Host: www.example.com

The web server on www.example.com will append the given path to the path of its root directory. On an Apache server, this is commonly /var/www/html. On an NGINX server, this is commonly /usr/share/nginx/html. The result is the local file system resource:

/var/www/path/file.html

/usr/share/nginx/html/file.html

The web server then reads the file, if it exists, and sends a response to the client’s web browser. The response will describe the content of the file and contain the file itself or an error message will return saying that the file does not exist or is unavailable.

Now, what can cause overload on your web server ?

At any time web servers can be overloaded due to:

  • Excess legitimate web traffic. Thousands or even millions of clients connecting to the web site in a short interval.
  • Distributed Denial of Service attacks. A denial-of-service attack (DoS attack) or distributed denial-of-service attack (DDoS attack) is an attempt to make a computer or network resource unavailable to its intended users;
  • Internet (network) slowdowns, so that client requests are served more slowly and the number of connections increases so much that server limits are reached;
  • Web servers (computers) partial unavailability. This can happen because of required or urgent maintenance or upgrade, hardware or software failures, back-end (e.g., database) failures, etc.; in these cases the remaining web servers get too much traffic and become overloaded.

What are the symptoms of overload ?

The symptoms of an overloaded web server are:

  • Requests are served with (possibly long) delays (from 1 second to a few hundred seconds).
  • The web server returns an HTTP error code, such as 500, 502,[5] 503,[6] 504,[7] 408, or even 404, which is inappropriate for an overload condition.
  • The web server refuses or resets (interrupts) TCP connections before it returns any content.
  • In very rare cases, the web server returns only a part of the requested content. This behavior can be considered a bug, even if it usually arises as a symptom of overload.

How can you handle overload before it happens? (Anti-overload techniques)

To partially overcome above average load limits and to prevent overload, most popular web sites use common techniques like:

  • Using Firewalls to block unwanted traffic coming from bad IP sources or having bad patterns
  • HTTP traffic managers to drop, redirect or rewrite requests having bad HTTP patterns
  • Deploying web cache techniques
  • Using different domain names or IP addresses to serve different (static and dynamic) content by separate web servers, e.g.:

http://images.example.com

http://example.com

  • Using different domain names or computers to separate big files from small and medium-sized files; the idea is to be able to fully cache small and medium-sized files and to efficiently serve big or huge (over 10 – 1000 MB) files by using different settings
  • Using many internet servers (computers) that are grouped together behind a load balancer so that they act or are seen as one big web server (Cluster Mode)
  • Adding more hardware resources (i.e. RAM, disks) to each computer
  • Tuning OS parameters to monitor capacity and usage

1 thought on “What is: Web server – Apache vs Nginx”

Leave a Comment