NGINX is often compared to the Apache HTTP Server, an open-source web server that’s been leading the market for more than 20 years. In this video, learn how these two web servers are similar and different, and why you might consider using NGINX instead of 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. In fact, the term LAMP is an acronym for servers that run Linux, Apache, MySQL, and PHP, a very popular application stack for delivering dynamic web content. So, you might be wondering, why use NGINX when Apache is such an integral part of delivering web content? 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 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 resources under very 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.
Programmers working with NGINX configurations might find this a bit more like programming compared to Apache, which might feel more like writing a document. Apache also provides for a distributed configuration through the use of .htaccess files. Each directory under the web server's root directory can contain a configuration file specifically for that directory. This has its benefits by allowing default configurations to be overwritten, but it also can 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 a directory, NGINX instead uses location blocks that can map requests to locations inside the web server's 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 eliminate the need for other applications. By including modules for languages like PHP, Python, and Pearl 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? While Apache maintains a strong lead in web server deployments, NGINX has been quickly gaining in popularity since its public release in 2004.
As more developers and engineers switch to NGINX, there's a noticeable decline in Apache's usage. Learning and using NGINX now will help you stay up to date with what may soon become 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 and 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.
- Installing NGINX on Linux
- Configuring a virtual host
- Installing PHP and MariaDB for the LEMP stack
- Securing sites with NGINX
- Creating SSL certificates
- Reverse proxies
- Load balancing