From the course: Learning NGINX
Comparing NGINX to Apache - Nginx Tutorial
From the course: Learning NGINX
Comparing NGINX to Apache
- [Instructor] We can't discuss NGINX without also taking a moment to reflect on the Apache HTTP Server. Apache, as it's more commonly known as, is an open-source web server that's been leading the market for more than 20 years. So you might be wondering, if Apache is such a popular web server, why use NIGINX? Or more fundamentally, what's the difference between Apache and NGINX? First, let's take a look at a few of the ways they're similar. Both Apache and NGINX are free and open-source software. This means that anyone can use the software without paying for it, and the source code is available for download along with binary versions of the application. This also means that the community of users behind both applications can review the code for bugs and vulnerabilities and suggest changes to be included in future versions. Both applications are compiled binaries, but they can be extended by dynamically including modules at runtime. This also allows users to add additional functionality as needed. Both Apache and NGINX can be configured as proxy servers, allowing them to pass requests onto other applications and then return the content back to the requester. And finally, NGINX and newer versions of Apache use event-based processing. This means they can both efficiently handle a large number of simultaneous connections. In past versions of Apache, each connection was handled by a worker process that required additional system resources for each new connection that was made. This could easily lead to a server consuming all system resources under heavy load. By adding event-based processing, newer versions of Apache are able to handle a high number of connections on par with NGINX. Now let's look at a few differences. One of the most obvious differences is the configuration format used by Apache and NGINX. Apache uses a format that's based on XML and can be verbose with open and closing tags for each section. NGINX, on the other hand, uses a syntax very similar to the C programming language with directives and blocks defined by opening and closing brackets. Developers working with NGINX configurations might find this a bit more like programming compared to Apache which might feel more like writing a document. Apache provides for a distributed configuration through the use of htaccess files. Each directory under the web servers root directory can contain a configuration file specifically for that directory. This has its benefits by allowing default configurations to be overwritten, but it can also slow down processing because the htaccess file must be processed before each request. NGINX uses a more centralized configuration with all configuration files loaded at the same time. Instead of configuring by directory, NGINX instead uses location blocks that can map requests to locations inside the web servers root directory somewhere else on the file system or to some other application for processing. Speaking of other applications, when it comes to processing dynamic content, Apache can minimize or even eliminate the need for other applications. By including modules for languages like PHP, Python, and Perl directly in its binary, Apache can serve these types of dynamic content on its own. NGINX would need to rely on an external application for dynamic processing. But when it comes to serving static content, NGINX takes the lead over Apache. In various tests, NGINX is found to be a little more than twice as fast as Apache when serving static content. NGINX also has built-in capabilities for caching content which can lead to faster responses from the server. Apache can be configured as a cache with a module but the configuration may be cumbersome. So with these similarities and differences to consider, why should we choose NGINX? NGINX has overtaken Apache as the most widely used web server in the world. By learning NGINX, you'll be ready to deploy the market leading web server. We've also discussed how NGINX is efficient and consistent under heavy loads. If developers are trying to deploy applications in environments that have limited resources, like small CPUs or limited RAM, deploying a web server that operates consistently can provide for more predictable performance. And along with efficiency and multiple capabilities, many find NGINX easier to configure than Apache. This can make NGINX easier to learn for people that are just getting into application development and system administration. Now that we have a better idea of why we should learn NGINX, let's get started.