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