Python for the .NET Developer Transcripts
Chapter: Deploying Python web apps
Lecture: nginx, you public facing web server

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well it's awesome that we got uWSGI working. But uWSGI is not appropriate for serving public-facing requests. I don't think it does SSL.
0:09 It doesn't handle static files very well. So we want a proper public-facing web service web server and that's going to be Nginx.
0:17 We've already installed it but we could always just double check over here. Says yep, it's there.
0:22 There's also this other random message we keep getting so I'm going to make that go away. So what we're going to do is we're going to disable
0:35 first I guess we could enable Nginx all together so that's going to start it up and let's just make sure it's good. We can say service nginx restart.
0:45 And what was our IP address over here? Let's go exit and I can come back. Be easy to copy. What happens if we request that URL?
0:55 Woo-Hoo, welcome to Nginx. You have a proper web server. Now go set it up. So this is like welcome to your IS website, right. This is just the empty
1:04 not configured thing. I don't want it to say that. So I'm going to delete that setting for handling random arbitrary sites over here, like so.
1:15 Let's see if it still says that. I'm actually not sure what it's going to say but, yeah, it's not happy. It's not listening.
1:22 That's good cause we don't want you listening to that one. Instead we want it to listen according to this. So here's the Nginx configuration file.
1:29 Want to start out by listing it on just HTTP. I'm going to listen to that domain but I believe it'll catch everything
1:35 if you have just one empty domain set up. We're going to map the static files so slash static is going to go to this folder, right.
1:45 This is the static folder of our web app we're trying to deploy and it's going to be cache for a year. Otherwise, we're just going to pass the URI
1:54 over to this thing which says we're going to just call basically pass it over to uWSGI and let it deal with it along with turning on GZip responses
2:04 including uWSGI parameters so they can play nicer. In order to make this work it's much like we had before. We just copy that config file over to
2:13 sites enabled guitary.nginx Let's try that. Here we go. service restart Now what do we get? Ta-Daa. It's beautiful. That really makes me happy.
2:26 It looks good, right? So we have it working, this is port 80 there's obviously an implicit 80 but the important thing to notice
2:34 is that it's not port 5000. In fact, if we try to go to port 5000 you can bet that that's going to time out because it's closed on the firewall
2:43 we're not listening to it all that kind of stuff. It didn't go there. We can check out the guitars and man, this site is flyin. Very, very quick.
2:51 If we go back over here and look you can see put that away and do some more clickin there you go. You can see the requests comin in.
2:59 I was trying to get fav icon but you know, that's a losing battle. We should probably put one in but. Anyway, guitars aug guitars acoustic and so on.
3:07 What's the response time? Zero. Holy moly, zero milliseconds. This one apparently was 16 milliseconds but this is some ridiculous performance.
3:16 Remember this is a $5 server this is not that big of a server. All right, well it looks like Guitari's up and running on port 80.
3:25 This is actually great.


Talk Python's Mastodon Michael Kennedy's Mastodon