Full Web Apps with FastAPI Transcripts
Chapter: Course conclusion and review
Lecture: Deployment

Login or purchase this course to watch this video and the rest of the course contents.
0:00 After we were happy with our app and we got it built and running, it was time to put it on the Internet,
0:06 and we decided Nginx plus Gunicorn would be a great way to deploy our FastAPI web application. Nginx is by far one of the most popular front
0:15 end web servers that handles things like static files, it handles SSL, and you know,
0:21 upgrades requests to things like HTTP2, all sorts of cool stuff that's happening over there.
0:26 It will be the front line server that our clients actually talk to. But when it comes to running, our Python code, our FastAPI code,
0:34 we're gonna do that, managed by Gunicorn. We already saw that Uvicorn, which comes from Gunicorn, is how we were, we've been running our app so far,
0:43 and we're gonna continue to use that in production, but not just by running it, but by having a bunch of them that Gunicorn can manage.
0:50 So it's gonna spin off 5, 10, who knows how many makes the most sense for your server and the number of requests
0:56 you're getting, but multiple numbers of your process as if you had started it just on
1:01 the command line multiple times. And then when a request comes in, Nginx is gonna figure out where it goes.
1:07 If it's a Python request, it hits Gunicorn and says, hey, drive one of these Uvicorn worker processes that's not busy. Well, this one,
1:16 it's not busy, it can handle a request. Another request comes in, says here, this one's not busy this time. Now then maybe those two are busy,
1:22 another request comes in, it picks this other one this next time. And this is generally how our web application works.
1:28 We saw that setting up Gunicorn to run, we had a special config file to do that as a systemd service. And then we have a special config file to set up
1:39 Nginx, and then we also had a whole script to actually build out the Ubuntu server just the way we wanted it.
1:45 It might be a lot to take in at the beginning, but if you go through it a few times,
1:48 you'll figure out what the important parts are to pay attention to, and the rest, you'll just copy and paste; and remember,
1:54 this script goes there and then we're good to go. Not too bad. So good luck running your app in production.


Talk Python's Mastodon Michael Kennedy's Mastodon