Full Stack for Front-Ends Part 2 Nginx Setup: proxy traffic to node server
This course has been updated! We now recommend you take the Full Stack for Front-End Engineers, v3 course.
Transcript from the "Nginx Setup: proxy traffic to node server" Lesson
>> Jem Young: So I want to Proxy Traffic Service to my Node Server. How do I do that? Anyone remember?
>> Jem Young: Nobody?
>> Speaker 2: Default.
>> Jem Young: Yes, default. So say sudo, actually, I will just cd into it, so you can take a look at it. Sudo/etc/nginx, LS all configuration for EngineX.
[00:00:23] So, let's see into sites available where the config file lies. LS, there's only one file. Default. The default? Right. EngineX configuration. So, I want a proxy traffic to my node server. So instead of location/. So you bang. I forgot the sudo that's. So all the traffic coming to my root.
[00:00:52] So just /akajem.party with no extra path on there. I just want to proxy that to node.
>> Jem Young: So that is proxy pass reset. Proxy pass directive.
>> Jem Young: And I want to say, you're running on localhost. So, 127.0.0.1 Port 3001. That looks about right. Yeah, that looks right. Oops.
[00:01:27] Not proxy directive. [SOUND] Proxy pass. Cool.
>> Speaker 3: In this case, it is the set over on the digitalation.
>> Jem Young: No. So, we're proxying to our local server on your local box. Also, right now you are on your server. We are editing the nginx configuration, on the server that we've been working on for the past few minutes.
>> Speaker 3: No, I kind of stuck. But I'm not on the [INAUDIBLE].
>> Jem Young: Okay.
>> Speaker 3: So this address is Digital Ocean server? No this [CROSS TALK] address.
>> Jem Young: So, you should be editing the nginx configuration on your server right now?
>> Speaker 3: I am doing it on just the lotion.
>> Jem Young: Your nginx configuration?
>> Speaker 3: Yeah. I installed nginx on digital lotion.
>> Jem Young: Okay.
>> Speaker 3: On the server.
>> Jem Young: The digital lotion server.
>> Speaker 3: Yeah.
>> Jem Young: Yeah. So, we are on digital lotion right now. Not our local Machine.
>> Speaker 3: I think you are on the same page.
>> Jem Young: Okay, yeah, [CROSSTALK] saying different things.
>> Speaker 3: So, this local is the DigitalOcean local?
>> Jem Young: Yes.
>> Speaker 3: Okay.
>> Jem Young: Yeah, sorry, when you say DigitalOcean I'm like, how'd you do that? You are better than me. Yes, and remember from the last course, 127.0.0.1 is just local host, which is the same as the loop back command.
[00:02:44] So that iss just saying, whoever we are, we're just gonna point back to our own port, which is 3001. That is our default port. Okay. Any questions so far? Cool. And useful command to make sure we typed everything right. If we say nginx -t
>> Jem Young: Perfect, it is gonna run our configuration file, and it is gonna just do a quick validation for us to make sure we did not mistype anything.
[00:03:11] Very useful command, because sometimes you'll try to restart nginx, and it just won't work. So let me just make a quick error to show you.
>> Jem Young: Let me just comment out this block.
>> Jem Young: Oops, wrong syntax.
>> Jem Young: And nginx is telling me that it's expecting a closing bracket.
[00:03:39] Pretty useful command, if you ever make some changes to Nginx, which, we are about to make a lot. And this is not working and the next very useful, very nice Just going to uncomment this again.
>> Speaker 2: Cool, so now let us restart nginx sudo service.
>> Jem Young: Nginx restart.
>> Jem Young: All right. But, right now we haven't done anything yet. So, if you are trying to hit it locally probably wont work, because we haven't done anything. We haven't started our node server yet. So let's go ahead and bring that up now.
>> Jem Young: So to do that, let's switch to our /var/www directory.
[00:04:32] And lets cd fe. Is everybody with me? We are now on our get repo that we just cloned. Hopefully, it installed all the node modules. So, now let's use forever. The very useful command. We'll say forever start. And our app is just called app.js, and it's up and running.
[00:04:56] Nothing to it.
>> Jem Young: Everybody with me so far? Yeah, so now let us go ahead and try to hit our brand new server from our box. We are gonna have to use IP. Because we haven't hooked anything up yet. Maybe we did. Let's give it a shot.
>> Jem Young: All right.
>> Jem Young: We're up and running, and hopefully I pointed this to the right address so, yes. jam.party is now pointed to my server. Is anybody lost so far? I notice some people having some trouble setting up their A records pointing to their domains of their server.
>> Jem Young: No problems?
>> Jem Young: Guy's we are on it. All right,
>> Jem Young: Yeah,
>> Jem Young: Not, yeah, not a whole lot happened here yet, but soon we will make magic using just Nginx, it's going to be great. And remember if you're having trouble how to set records, how to point a domain to from an IP, in A record, we're gonna use host@, then we are going to use that's gonna be jump a party, dub dub dub.jam that party, and we're just pointing it out to an IP address.
[00:06:24] And if you are thinking right now, hey, the firewall's open, I didn't open it. When you install EngineX, by default it opens port 80 for you. Very nice, it's very helpful.