RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Deploying your REST service to DigitalOcean on Ubuntu
Lecture: How we deploy Python on nginx, uWSGI, and Ubuntu

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We've reached an exciting point in our class, we've basically entirely created our web api,
0:07 and we're ready to deploy it to the cloud, in a full on production environment. I hope you're excited, I am. So how is this going to work?
0:15 Well we're going to start out by deploying this to Ubuntu, that's this big grayish box here, right so we're going to deploy to Ubuntu,
0:22 and we could have the running across multiple servers, with load balancing a lot of things, but for a simple example
0:28 we're just going to put it all on the same machine. So the first technology in addition to Linux that we're going to employ is nginx,
0:35 so nginx is going to be the front line web server, this is the thing that browsers and other web clients talk to,
0:44 and as far as they know this is the only thing involved in our web processing, so then, behind the scenes on the server,
0:50 the thing actually executing Python is going to be μwsgi, μwsgi is implemented in C and is specially built
0:59 for running Python web applications, so we're going to run that, but we're not just going to have one instance of it,
1:06 instead we're going to use it in this kind of master emperor mode I think it might be called,
1:13 where there's one process, but you actually create many subprocesses because Python is not super great at computational parallelism,
1:21 so the way we're going to solve this is just by having many subprocesses, it does use threads and as we're talking to things like databases,
1:27 that will do parallelism, but we're going to get additional parallelism by having multiple ones. So we're going to create a bunch of these,
1:34 and it's actually in these little sub processes where our Python code is going to execute,
1:39 so let's see how this request overall architecture is going to work, some kind of request is going to come in from the internet,
1:46 and hopefully, you'll set this up to use https, it's really easy to make nginx talk https,
1:51 you just get a certificate, point it at it and say here's your certificate, so a request will come in to nginx,
1:57 it's going to handle all the ssl certificate stuff, all the static files and things like that
2:02 but when it needs logic, when it needs to do Python stuff in our application, it's going to send this request internally
2:09 over to our μwsgi management main process, and this is probably over http or just a local socket,
2:15 and then this thing is going to decide which one of these is going to actually do the processing and then it will return the response back,
2:22 so this is what we are going to go now and set up on Digital Ocean we are going to create an Ubuntu Server on Digital Ocean,
2:28 we are going to install nginx, we are going to install μwsgi, we are going to move our Python code that we've written up there via get,
2:34 and then we're going to see how to configure these things to accomplish
2:38 basically exactly what I have here, except we're not going to do the https part, you guys can add that on yourself if you want.


Talk Python's Mastodon Michael Kennedy's Mastodon