This article discuss some points about two major web servers Apache and Nginx.
Apache is the most popular web server since 1996. Apache software foundation doing the development and maintenance of this software. The first version of Apache web server software was developed by Robert McCool,who was heavily involved with the Nation Computer for Supercomputing Applications web server, known simply as NCSA HTTpd. When McCool left NCSA in mid 1994, the development of httpd stalled, leaving a variety of patches for improvements circulating through emails. These patches were provided by a number of other developers besides McCool, and they thus helped to form the original “Apache Group”.
Apache is a modular server, this implies that only the most basic functionality is included in the core server. Extended features are available through modules which can be loaded into Apache. By default, a base set of modules are included in the server at compile time. If the server is compiled to use the dynamic modules, then modules can be compiled separately and added at anytime using the LoadModule directive. Otherwise, Apache must be recompiled to add or remove modules.
/usr/local/apache/conf/httpd.conf or /etc/httpd/conf/httpd.conf
Apache directives are a set of rules which define how your server should run, number of clients that can access your server, etc. you can change them by editing the httpd.conf and related files to meet your requirements. Some of the important directives are given below;
1.Allow Override: It defines which directives declared in that file can override the earlie configuration directives.
2.DirectoryIndex: Defines Index page served by the server.
3.Timeout: Defines in seconds, the amount of time server waits for receipts and transmissions during communications.
4.KeepAliveTimeout: Sets the number of second the server waits after a request has been served before it closes the connection.
5.KeepAlive: Enable server multiple requests on the same connection.
6.MaxKeepAliveRequests: Defines the maximum number of requests allowed per persistent connection when keepalive is on.
7.MaxClients: Sets the number of simultaneous requests that will be served.
8.MaxRequestsPerChild: Defines the number of requests a child process will handle.
Multi-Processing Modules enables the server to handle more than one request at a time. Apache offers three MPM to choose from, prefork,worker,event. Sites need a great deal of scalability can choose to use a threaded MPM like worker or event. Websites requiring stability or compatibility with older software can use prefork.
Enhancements in apache 2.4 version
Run-time Loadable MPMs: Multiple MPMs can now be built as loadable modules at compile time. The MPM of choice can be configured at run time.
Event MPM: The Event MPM is no longer experimental but is now fully supported.
Asynchronous support: Better support for asynchronous read/write for supporting MPMs and platforms.
Per-module and per-directory Loglevel Configuration: The LogLevel can now be configured per module and per directory.
KeepAliveTimeout in milliseconds: It is now possible to specify KeepAliveTimeout in milliseconds.
NameVirtualHost directive: No longer needed and is now deprecated.
Override Configuration: The new AllowOverrideList directive allows more fine grained control which directives are allowed in .htaccess files.
Reduced memory usage: Despite many new features, 2.4.x tends to use less memory than 2.2.x.
1.Openness, can be sourced free of cost.
2.Supports wide range of programming languages like PERL, Python and PHP.
3.Portability, operating systems like Unix, Linux, Windows NT, Mac OS supports apache.
5.Reliability, source code open to public, bugs get communicated and easily fixed. These bug fixes and solutions provide a greater security and stability to apache web server.
Nginx (pronounced “engine-x”) is an open source reverse proxy server written to address some of the performance and scalability issues associated with Apache. Written in C by Igor Sysoev, a Russian software engineer. Initial release 6 August 2002; 11 years ago. Licensed under 2-clause BSD-like license.
The need for serving large number of concurrent requests is raising every day. The prediction of C10K problem (i.e 10,000 concurrent clients) started the research on web server architecture which could solve this problem. As a result Nginx architecture was developed. The web server scalability problem can be solved either by increasing the hardware capabilities (i.e memory, CPU, etc ) or by improving the web server architecture. The goal here is to improve the web server architecture to optimize the hardware resources, which will eventually lead to a cost effective architecture.
Nginx architecture is a modular, event-driven, asynchronous, single-threaded, non-blocking architecture which became the foundation of nginx code. Connections are processed in a highly efficient run-loop in a limited number of single-threaded processes called workers. Within each worker nginx can handle many thousands of concurrent connections and requests per second.
By Event-driven it means that notifications or signals are used to mark the initiation or completion of a process. Thus, the resources can be used by other process until a process initiation event is triggered and resource can be allocated and released dynamically. This leads to the optimized use of memory and CPU. By Asynchronous it means that the threads can be executed concurrently with out blocking each other. It enhances the sharing of resources without being dedicated and blocked.
By Single threaded it means that, multiple clients can be handled by a single worker process as the resources are not blocked.
Configuration file. The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory/usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.
user www www;
error_log /var/log/nginx-error.log info;
Event Notification in Nginx
There are three methods of event notification in Nginx.
select and poll
Like Apache, Nginx has all the features you would expect from a leading Web server:
Static file serving.
Nginx Vs Apache
1.Nginx is based on event-driven architecture. Apache is based on process-driven architecture. It is interesting to note that Apache in its earliest release was not having multitasking architecture. Later Apache MPM (multi-processing module) was added to achieve this.
2.Nginx doesn’t create a new process for a new request. Apache creates a new process for each request.
3.In Nginx, memory consumption is very low for serving static pages. But, Apache’s nature of creating new process for each request increases the memory consumption. Several benchmarking results indicates that when compared to Apache, Nginx is extremely fast for serving static pages.
4.Nginx development started only in 2002. But Apache initial release was in 1995.
5.In complex configurations situation, when compared to Nginx, Apache can be configured easily as it comes with lot of configuration features to cover wide range of Requirements.
6.When compared to Nginx, Apache has excellent documentation.
7.In general, Nginx have less components to add more features. But Apache has tons of features and provides lot more functionality than Nginx.
8.Since Nginx comes only with core features that are required for a web server, it is lightweight when compared to Apache.
9.The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU.
10.Serving 10,000 simultaneous connections would probably only cause Nginx to use a few megabytes of RAM whereas Apache would probably consume hundreds of megabytes.
There are no revisions for this post.