What is Nginx?
Nginx (pronounced “Engine-X”) is an open source, high-performance Hypertext Transfer Protocol (HTTP) server. In technical terms, it is an event-driven asynchronous server. This means the method by which Nginx handles processes (required for loading web content, for example) is driven by conditions and delegated to alternative server resources to bear the load accordingly. Nginx is typically used to exploit higher performance from minimal resources, for example, on a VPS platform.
Nginx is versatile, in that it can be installed to replace Apache as the HTTP server. Because of its flexibility and lightweight design, it can also be installed along side Apache. In this manner, Nginx would be referred to as a reverse proxy.
How does Nginx compare to Apache?
On our servers, Apache is the default HTTP server that is configured for handling PHP processes to serve web content. In its default configuration, Apache is designed as a process-based architecture. This means that Apache forks (or threads) each process that is needed to serve web content.
Nginx alternatively scales these processes to help decrease the amount of CPU, RAM, and other server resources utilized, thus improving the load time. For instance, if one connection requests the same content as another, rather than processing those requests individually, Nginx analyzes and delegates accordingly. Both connections receive the same results of content loaded.
Although Apache and Nginx performance can both be similar in comparing load handling for small sites, Nginx’s architecture, by design, is more efficient for heavier sites. However, the benefits of Nginx can be experienced with simple web applications, like WordPress. A common configuration that is implemented to improve the handling of a high load, is to setup Nginx as a reverse proxy.
What is a Reverse Proxy?
A Reverse Proxy is a type of configuration in which a proxy server off loads a request to another web server (or multiple servers) to execute processes. When the results of the request are received by the proxy, it is then returned to the client. This kind of proxy results in the ability to cache dynamic content without having to continuously rely on the server’s resources for each request to load the same content. This results in a reduction of resources (like CPU, RAM, I/O) utilized and thus improves the performance of your site.
How Does It Work?
Putting this all together, typically server administrators will combine the use of Apache and Nginx as a reverse proxy to decrease the server resources needed to load a site’s content. Depending on Nginx’s configuration, when requests are made, it will first check to see if the processes have already been completed.
If the results of the requests do not exist, then Nginx will provide the requests to Apache for processing. Apache will handle the requests (forking/threading the requests) and then return the results to Nginx to serve to the client. If configured, it will also keep the results of the requests cached. This allows Nginx to quickly retrieve and serve them to any other connections that are requesting the same content.
If the results of the requests already exist, then Nginx will quickly retrieve and serve the cached content. Nginx may also be configured to analyze the cached version and update it with changes accordingly. Therefore eliminating the need for Apache to do anything for repeated visits/connections, even as content is updated.
Don’t worry, you can configure Nginx to handle your WordPress site so that your visitors will be able to see your site’s updated content and not just an outdated cached version. Included with your WordPress-optimized server, is the cPanel plugin, Cache Manager. For more information on how you can simply leverage Nginx’s caching resources, review our article on the Cache Manager for cPanel.