Apache operates in "prefork mode," employing a predetermined quantity of processes, each dedicated to handling one request at a time, whether static or dynamic.
In contrast, NGINX takes an asynchronous approach toward requests. A single NGINX process can effectively handle numerous concurrent requests, limited only by the available system resources.
Unlike Apache, NGINX does not integrate server-side languages directly into its processes. Instead, NGINX forwards these requests to an external process, such as PHP FPM, for server-side processing.
NGINX excels at delivering static files rapidly, with the server-side processes remaining oblivious to this operation. Conversely, Apache handles all resources with server-side overhead, leading to a greater consumption of server resources compared to NGINX.
Performance
NGINX: Swift Handling of Static Resources
NGINX: Support for Higher Concurrent Requests - Capable of managing thousands of requests on a single thread.
Apache: Serves requests up to a pre-configured limit, rejecting any exceeding requests.
NGINX wins!
Configuration
- NGINX prioritizes URI locations, while Apache favors file system locations as a primary consideration.