Geek Culture
Published in

Geek Culture

My SDBA Coding Bootcamp: Episode 6

Port-a-Port.

This is what learning Nginx felt like at first. Credit to Beasty . on Unsplash. Yes, that really was their username. Apparently the beast is in the present directory.

Ok, I lied in the last part (*SLAP goes the Internet ruler*). I am really not sure what to do here next. How many times do you configure an nginx before you know how to configure an nginx? Apparently three. I think I do know what to write about tonight, the same thing I had always been writing about: how to stumble through a tech project with the confidence of someone who thinks she can take over the world and hope Pygmalion does its magic.

So in situations like this, I like to start with what I know and work towards what I don’t. I know I exist, and that my thoughts are real, so if I think….oh wait, wrong existential crisis. So we know that we need to deal with the nginx.conf. I have to always remind myself what a default looks like. Here is a fairly minimal nginx.conf:

daemon            off;
worker_processes 2;
user www-data;

events {
use epoll;
worker_connections 128;
}

error_log logs/error.log info;

http {
server_tokens off;
include mime.types;
charset utf-8;

access_log logs/access.log combined;

server {
server_name localhost;
listen 127.0.0.1:80;

error_page 500 502 503 504 /50x.html;

location / {
root html;
}

}

}

I am not going to walk through what every line does here. There are many sources that do that better, albeit hard to find. Here is where I pulled this code snippet from, and they seem to explain the Nginxish well enough. If looking at the above code makes less sense than reading pig latin, (unless of course you are a pig and/or work on Wall Street), you might want to start with the source I linked. For now, all we care about is that server context, I think.

server {
server_name localhost;
listen 127.0.0.1:80;

error_page 500 502 503 504 /50x.html;

location / {
root html;
}

Hold please

I am back several (about 23) hours later — although it’s a few seconds for you, I know (unless you also went and got coffee for the third time like I did). So I went and really studied Node and got flashbacks to college minus the imposter syndrome. So I think I have a very basic idea of what to do for the app.js in order to see if it will talk to nginx (Warning: don’t just copy and paste this code into your own whatever — I am not sure it will work. If that bothers you, you are in the wrong f****** place).

const http = require('http');const server = http.createServer();
server.listen(3000);
console.log('Cash me on port 3000....')

Let me see if I can explain this simply but enough to make you feel like you learned something from my fumbling. In JS, you import modules and shit by requiring it and assigning it to a constant variable. This took some getting used to because in Python it is like import thing and that’s it. Also fun fact: Node has to have EVERYTHING IT WILL USE imported apparently. Whether that is good or bad is up to you and how much you feel like fighting me in the comments I guess.

So first I will mk a dir called sdba-project(I am sure I can rename it easily later…………………………………………………). Then I will vim what I had above into sdba-project/app.js. (Or emac. Whatever will piss you off more).

Let’s try node app.js. I fully expect some shit to go to f*ck, but I want to see what happens because I am new here.

Then I am going to hit ctrl+z to put it to the background.

Nevermind, that is not a thing here.

But wait, the article I just inconspicuously linked to talks about when closing the terminal. But has not closed ze terminal. So lemme try something…

So why the f*** did it say stopped earlier? Was it just referring to the showing of the console log? Help.

But really we have gotten what we came for. Remember this line from earlier?

Yes I screenshotted my own article; come fight Medium code formatting and then me.

I think server_name will become 3000. As an aside that you will kiss my feet for later:

Always sudo vim file/that/is/in/root. You will get reminded of your grade school days when you spent all this time writing a paper only to have Microsoft word crash or something. Instead here, vim will cheekily tell you you don’t have permissions to edit the file after you have already made changes.

*Nervous laugh*

So apparently my configuration was not as conventional as I thought it was…..So the nginx.conf in MY particular system didn’t have the server stuff, but did refer to a default.conf in the /etc/nginx/sites/enabled folder. TBH, that is the first time I have seen that configuration. I think every system I have worked on Nginx and lodged itself into the filesystem in a different way every goddamn time.

Well, let’s see how much read time am I at?

Well, shit. I probably should add a few more minutes. Ok, let’s play around a bit to see what we can learn. So in the ACTUAL default configuration file, the server stuff looks like this.

There is something that has been bothering me, and I think it is going to be relevant here. Why is it sometimes 0.0.0.0:port and sometimes [::]:port? Sometimes there is both:

Well shit, here it is ::::80. Does the not having brackets matter or is my autistic literalism kicking in again? To Google!

…..

This was kind of hard to google, but I think I lucked out. https://www.digitalocean.com/community/tutorials/haproxy-network-error-cannot-bind-socket

It gets mentioned off-handedly here:

Oh, so maybe that is why THERE WAS A FUCKING 6 NEXT TO THE TCP HERE:

I’m done for tonight.

https://twitter.com/Sc00tr_Grrl/

I don’t really understand the previews for links here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shelby Elzinga

Shelby Elzinga

THE scooter girl. Jill of all trades. Mostly best at failing at tech. Needs to get better at writing bios.