Nginx

1) Nginx (aka engine-x) acts as a reverse proxy

2) Parallel processing of requests : It handles concurrent requests

3) Load balancing : If there are two or more webservers, running the same application, nginx can route the traffic or even distribute the load among webservers

4) When using SSL, an extra overhead is required by the webserver to encrypt/decrypt. With Nginx acting as a reverse proxy, this work can be done on nginx and back-end webserver no longer have to deal with SSL.

Apache vs Nginx

Apache : A thread is blocked until the request is complete.

New request --> new thread spawned --> proceeses request / passes request to other server --> releases thread only when reponse is received.

Analogy: Mcdonals. Blocking people in queue till the order of the person before you is complete.

Nginx : A single thread is used for accepting request, and passes the work to other worker threads

New request --> event thread accepts request --> passes request --> event thread is now free --> response returned asynchronously.

Analogy: Take away restaurnt: Place order and become free. You are called when order is ready

Apache is used in cases where you want the server to process request(eg, serve dynamic content). Nginx is used when you want a reverse proxy to just pass the request. In some cases, both are used along slide each other

Nginx has an advantage here when dealing with large data. For eg, what if a request was to stream a 1hr long video? In apache, a single thread will be blocked for this task. But nginx uses event based architecture (discussed later), which eliminates this problem and makes it suitable for streaming media

In apache, the number of concurrent requests is limited by the number of thread the machine can spawn. Therefore, a costlier machine may be required to serve concurrent requests. In nginx, there is not such limit. Even a cheaper system can handle thousands of concurrent request. (However, response of the request depends on application implementation)

NOTE : For Django, we will not be dealing with apache