Skip to content

Web Server and Nginx

In this video, we are going to learn about web server and nginx.

Web Server

At first, let us discuss about web server.

A web server is basically a software application that takes requests from clients and returns a response . This response can be in the form of HTML pages, images, videos, or any other type of data that makes up a web page.

Web servers are responsible for processing requests, routing them to the appropriate parts of the application, and returning the corresponding responses.

In the context of Django, the web server is the component responsible for receiving incoming requests from users' browsers and passing those requests to the Django application for processing.

The Django application then generates a response, which the web server sends back to the client.

WSGI, ASGI

Now, you have learnt what a web server is, lets discuss about WSGI and ASGI.

In python, when you deal with the web server, you will often encounter two terminology: WSGI and ASGI

WSGI is a protocol and specification that allows synchronous communication between webserver and our django application. WSGI stands for Web Server Gateway Interface. Gunicorn is one of the most popular wsgi web server in python ecosystem.

ASGI is a protocol and specification that allows asynchronous communication between webserver and our django application. ASGI stands for Asynchronous Server Gateway Interface. Uvicorn is one of the most popular asgi web server in python ecosystem.

So, if your django application contains synchronous code, then you should use wsgi server like Guniorn and if your django application contains asynchronous code, then you should use asgi web server like Uvicorn.

In this course, we have wrote all our code in synchronous way. So, we will be using gunicorn as our wsgi webserver to server the web traffic from internet.

NGINX

Now, lets discuss about nginx.

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. In simple words, it is a web server that has capability to handle incoming web server, act like a reverse proxy and serve our images and videos files.

In this course, we will use Nginx as a reverse proxy and to serve our static assests.

Now, previously, I explained about webserver like Gunicorn and Uvicorn. The major drawback of these webserver are they are not able to serve our static assets. Also, they lack proper load balancing mechanism, media streaming and security mechanisms. They are great to take request and pass it to django and return the response back to client.

So, we will use nginx as a reverse proxy and to serve our static assests.

Reverse proxy simply means that, client will send request to nginx and nginx will pass that request to gunicorn and gunicorn will pass that request to django and when django returns the response back to gunicorn, then gunicorn, will return that response back to nginx and nginx will return that response to the client.

So, here nginx is at the middle of our gunicorn and client. It is acting like a proxy to serve request from our gunicorn and django application.

Whereas, we will also use nginx to serve our images and static files like css, of our django project.

So, in this video, we discussed about web servers, wsgi, asgi and nginx and in the next video, we will learn how to deploy our django project in a ubuntu machine.