Check out a free preview of the full Full Stack for Front-End Engineers, v2 course:
The "Nginx Configuration" Lesson is part of the full, Full Stack for Front-End Engineers, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Jem demonstrates how the Nginx server is configured, how to create an HTML page, and how to make it the default page that will appear on the browser when connecting to the server.

Get Unlimited Access Now

Transcript from the "Nginx Configuration" Lesson

>> Jem Young: All right, Nginx is serving us a page. But where did that come from? What is it doing? Let's take a look. So, let's look at the Nginx configuration. And we're gonna spend a lot of, well, we're gonna spend a fair amount of time in the Nginx configuration.

[00:00:14] So, let's get familiar with it. So, sudo less or vi or cat or whatever you want to do, but up for less etc Nginx sites available and we're going to use the default configuration. And remember you can tab complete most of this. So I will say sudo less etc nginx sites-available, and default, cool, and it's a lot, I know it's a lot.

[00:00:52] Nginx kindly provides comments in here, links to start reading. I'll warn you now the Nginx documentation is not pretty. It's good. It's thorough, obviously, but it's not the most readable thing you're ever going to run across. So generally, if you're talking about tweaking Nginx, it's better to do Google search on it and read a blog post on somebody that's talked about it.

[00:01:13] Almost everything want to do in Nginx someone has done before. So that's a better way to go. However, if you really want to, read the docs. I don't recommend it. You can also use the man page, I don't recommend that either. [LAUGH] But it's there if you need it.

[00:01:25] And we'll talk more about that in a second.
>> Jem Young: So with Nginx configuration there's a lot of different things, I'm gonna try to highlight them today. The bass directory for all requests are going to go to slash var dub dub dub slash HTML. That's where all requests are going to go by default.

[00:01:47] And we're going to keep that directory cuz it's just the nice place to keep all your web stuff. You can move around if you want, but slash var slash dub dub dub is usually where people keep most of their applications and things like that. But you can move it to wherever you want.

[00:02:01] A location block is just saying for every request that comes into the server, what should I do? And Nginx regular expressions here, in this case it's just slash it's gonna match everything coming in. It's gonna try to serve the file, so it's gonna serve one of these. And if it doesn't, it's just gonna 404 page.

[00:02:20] We're gonna use the location blocks slash for most of the things we're gonna do today. We're not gonna create paths or subdomains or things like that. But that's just called a location block. This try underscore files, it's what's known as a directive in Nginx. Essentially, it's a called a macro for doing something.

[00:02:38] The one we're gonna use a little bit later is proxy past which we'll talk about. And that's gonna proxy your request to some other part of the server. But try files just means it's gonna try to look up one of these files. And if it can't any of them, it's gonna 404 page.

[00:02:51] It's gonna say error, right? So here we are, we have a server block in Nginx configuration. It's a default server, so it's listing on port 80. All this stuff's there. There's a root directory, the server name, which we'll change later, but for now we don't need to because it's the default server still accepting connections from everywhere.

[00:03:13] Here's a location block. You can ignore the rest of this for now. This is your Nginx configuration. So let's tweak it a little bit and quit just q. So for now, that default page came out of magic mystery land. Let's go and create one and then edit it to change to whatever you want.

[00:03:33] It's going to change the default page because that way you know your directories are working, and the files are working, and it's serving correctly. So, sudo vi/var/www/html and then create an index.html page. So, I'm going to go ahead and do that here. Sudo
>> Jem Young: I know what you're thinking that's not proper HTML, doesn't matter.

[00:04:06] It will work. If I try to do anything fancy, like styling, it's gonna break. But for now, you don't have to write an entire HTML page. If we had more time, I'd say who can create the best HTML page in 10 minutes. And I feel bad cuz I beat you.

[00:04:20] So, I'm kidding, I wouldn't, that is not my forte. This is more my area of expertise. But we're just going to wq that and when we refresh our page before we now have a different page because instead of looking to that default Nginx page, it's looking in order in index dot HTML comes in order.

[00:04:40] Everybody here so far? Cool. Now we're doing something, we are now serving an HTML page on our own server. I know little things. I think it's cool. Good job.