Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: Configuring nginx

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm pretty sure we already have Nginx installed
0:02 Let's just double check here.
0:04 It's already there, already set up, everything is good.
0:07 Great, so what we have to do is we have this
0:09 other Nginx file and let's look at it really quick.
0:12 It says you're going to listen on port 80.
0:15 You're going to listen to this, we can even put
0:17 things like www that, and so on.
0:20 As many domains, names or subdomains as you want up there
0:24 we're just going to listen on this main one.
0:26 Put a few limits, and configuration there, and then it says
0:29 Nginx itself is going to handle all of our static files
0:32 our CSS, our JavaScript, everything.
0:35 And it's going to find those right here
0:37 and it's going to actually cache them
0:39 for a year which is pretty sweet.
0:41 And then what it's going to do, it says
0:42 look, if somebody goes anywhere other than /static
0:46 we're just going to go and pass that URL on to here.
0:50 This is exactly how we've configured uWSGI
0:53 already so just to confirm, perfect.
0:57 So it's just going to delegate that across.
1:00 It's also going to pass the real IP and host name
1:03 because that stuff gets lost in this configuration
1:06 if you don't pass it through
1:07 that's a new header you got to ask for.
1:09 So this should be good and what we're going to do
1:11 is where going to remove any default
1:13 website that Nginx may have and we're
1:15 going to give it this one instead.
1:19 Be careful about doing that if you care
1:21 for it being there but we've gotten rid of it
1:23 'cause we don't want to use it, we don't care.
1:25 Go like this, and now last thing to do is just
1:28 update Nginx like we did in uWSGI
1:31 just start as a service.
1:33 And restart it or start it if it's not running
1:37 let's see about this, http://localhost.
1:40 Boom. It's working.
1:42 You know what we can do now?
1:43 We can do better than that, we can come over here
1:46 and say HTTP:// I think I call it.
1:52 Bam, there it is.
1:54 It's up on the internet, let's go log in.
1:57 Yeah I know it's not secure. There's my account.
2:01 The reason it already exists is we copied
2:03 that SQLite database so it was already there.
2:06 Isn't this cool? Look how quick and speedy this thing is.
2:11 If we come along let's do a little
2:14 inspect element with the network and just look at HTML.
2:17 So if we hit this a few times
2:19 our ping time is around 30 to 40 milliseconds
2:22 and the response time all the way back here
2:24 to my browser is 50 milliseconds.
2:26 That is super, super sweet.
2:29 So really really digging it
2:31 looks like our server is up and running.
2:33 Let's just do one more thing just
2:34 to prove everything is good, let's just reboot the server
2:37 and make sure it all comes back.
2:38 There's nothing we have to do, we've already done it
2:40 I just want to show you that it's all configured.
2:50 There we go it's alive, let's see if it still works
2:51 as we click around, account, yeah it looks live to me.
2:55 Let's logout, bam, just like that.
2:58 Our server is up and running and there's a lot of details
3:02 in these files here but nothing magical
3:06 and I'm giving them all to you
3:07 and they're ready to just take them
3:09 and configure your server and your app as you see fit.