#100DaysOfWeb in Python Transcripts
Chapter: Days 89-92: Deploying Python web apps to Linux
Lecture: Deployment moving parts overview
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's look at some of the architecture and technologies involved in this deployment. Now, this big gray-ish box here, this has the Ubuntu logo.
0:08
This is our Linux machine where we're going to deploy our Python web application. Now, a couple of pieces of software are going to be involved.
0:15
We're going to use something called Nginx. Nginx is the thing that your browser will talk to. This will be what people consider
0:23
to be your web server when they hit your domain. The domain will say, the response will indicate this is an Nginx server.
0:31
All the SSL will go through here. All the static files will be directly served by Nginx.
0:37
But anytime a data-driven request comes in, one that's going to hit a Pyramid view method, then it's going to run in this other process called uWSGI.
0:47
WSGI, W-S-G-I, stands for Web Service Gateway Interface. This is a common interface, a common API that all the Python web frameworks speak.
0:56
Pyramid, Flask, Django, and so on. The micro, I'm guessing, is it's lightweight. These are the two applications we're going to run
1:03
and they're going to run our Python code. There's going to be one Nginx process and it will delegate these data-driven requests
1:10
over to the uWSGI process. Python doesn't have amazing single-process parallelism. It's async and await features, it's asyncio features
1:21
are really awesome, but these frameworks don't have that typically. Flask, Pyramid, Django, none of them at the time of recording, do.
1:29
Remember, we talked about Quart, for example. Instead of just running one process and even if we had the parallelism
1:35
we get better scalability if we run more than one process. So, uWSGI will operate in this Emperor mode where there's one process of uWSGI
1:44
that controls a bunch of others. In those other worker processes that will be where the actual Python code runs.
1:50
These little processes with the Python icon that is where your Pyramin, Flask, and Django actually runs. Let's see how a request might be processed.
1:59
Comes in, probably over HTTPS, hits Nginx. That decrypts the traffic that starts processing the request
2:06
and then it's going to foreword that over to uWSGI. uWSGI's going to say, okay, which one of my worker processes
2:12
is not busy, or is less busy, right now? How 'about this one? This one on this particular request is going to process it.
2:20
Now, another request comes in, it's going to say actually, let's let that one process the next request.
2:25
While those two are running, maybe a third request comes in it says, oh, this one, this time is going to get to process it.
2:30
You'll see, we'll actually have multiple copies of our web server running and it's super easy to configure how many of those you have.
2:38
This is the overall workflow and the set of software we're going to work with. Our first task is going to be to set up Ubuntu.
2:45
Our second task will be to set up uWSGI. And then finally, we'll set of Nginx. Once we have Nginx running
2:52
everything will be listening on the public internet and we'll be able to actually deploy our web app. That'll be awesome.