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