Web Server and Application Server in Django

Web vs. Application Server Dynamics in Django

As explained in the beginning of this chapter, two types of server functionalities are required for dynamic web applications – a web server and application server. The key difference between those two servers is that a web server manages static content while an application handles dynamic content.

The main figure illustrates a use case in Django applications using Nginx as a web server and Gunicorn as an application server. As Nginx handles all requests from clients first, it is also called a reverse proxy server.

The mechanism is as follows:

  1. Using the collectstatic command, all static files are stored in a particular location that Nginx can also recognize. (This is important for Nginx configurations. We'll explain this later.)
  2. When an HTTP request for static assets comes, Nginx handles the request directly. The static URL is defined in the settings.py (STATIC_URL).
  3. When an HTTP request is not for static assets (request for dynamic content), the request goes through Gunicorn, and the Django app handles the request using the URL dispatcher, Views and Models, etc.

You can also learn this topic offline. Click AmazonKindle.