Nginx vs Apache
‘Chris recently joined us during Codementor Office hours and answered some of our viewers’ questions about Nginx. Here is one of the questions he answered: Nginx v.s. Apache.
The text below is a summary done by the Codementor team and may vary from the original video and if you see any issues, please let us know!
Nginx vs Apache
Nginx and Node.js can speed up performance and perhaps offer some advantages to concurrent connections. How is it better or worse than Apache?
Nginx and Node.js are similar, since they both have a single or low number of processes. They’re also both asynchronous and evented, so their way of handling processes and requests is fundamentally different from Apache in that respect.
Apache will try to make new processes, new threads for every requests in every connection. Nginx, like Node.js, will not do that. It has few numbers of processes and will take new requests as they come, but because it’s asynchronous it can just start to process a request. In other words, if something is taking a long time, it can do something else (e.g. another request), and then come back to another one when something has finished happening.
If you’re familiar with coding in Node.js, you’d know that it has call backs, that something can happen and you don’t know when it’s finished until you get a call back from the thing that is finishing. Even though it doesn’t actually make your application faster, it is better for handling a high number of concurrent requests because it can handle operations in a non-blocking way. In other words, it doesn’t make you wait for a file operation or a network operation before it moves onto another pass. Therefore, in that respect I think it’s better than Apache. Apache can do a lot of stuff such as handle a lot of traffic, but Nginx and Node.js are a fun combination because they both have a really similar way of handling request responses and processing HTTP requests.
Other posts in this series with Chris Fidao:
- PHP Office Hours: How to Use Nginx With Your Web Application
- Things You Need to Take Care of When Setting Up a New Server
- Nginx Tutorial: Serving Static Content Without Using a Directory
Or Become a Codementor!
Codementor is your live 1:1 expert mentor helping you in real time.