DNS, Nginx & Node.js

Understanding Web Infrastructure

DNS

What is DNS and why does it exist?

DNS or Domain Name System is called "the internet's phonebook". It translates human-readable website names into numerical IPs that computers use to find each other and load web pages. Without it, we'd have to type long numbers (IPs) into the browser every time.

How does it work?

  1. You enter a domain name such as example.com into your browser
  2. Browser asks DNS: what's the IP to this domain?
  3. DNS servers find the IP
  4. DNS responds with an IP address returned
  5. Browser connects to the website and loads the page

How is DNS related to a website's name?

When you buy a domain, you must set DNS records that point to an IP address. If you don't, DNS has nothing to return, so the website cannot be found.

At first, the domain is basically saying: "I exist, but I don't point anywhere yet."

In simple words:

  • A domain by itself is just a label
  • DNS needs instructions
  • Those instructions are DNS records

So no record = no destination

Note: You'll see errors like "server not found" or "DNS_PROBE_FINISHED_NXDOMAIN"

DNS Record Types

A Record

To make a website reachable, you need to point it to an IP address using an A record.

example.com → 200.0.187.45

CNAME Record

A CNAME (Canonical Name) record acts as an alias. Instead of pointing directly to an IP address, it points one domain name to another domain name — as long as it eventually reaches an A record.

Note: "Canonical" means the official/real/main version of something.

So when you create a CNAME record, you're saying:

  • This name is not the real one
  • The real (canonical) name is over there

NGINX

Nginx is a low-memory-usage, open-source software that handles, accepts, and manages many simultaneous browser connections at once.

For each incoming request, Nginx can either serve a static file itself (HTML, CSS, images) or forward the request to another service like Node.js.

In short, Nginx:

  • Accepts connections from the internet
  • Handles HTTPS and security
  • Sends requests to Node.js
  • Sends responses back to users

NODE.JS

Node.js is a program that handles requests from the web and allows developers to run JavaScript on the server to create dynamic content or data before being sent to users.

How does Nginx handle connections to Node.js?

By acting as a reverse proxy server.

It's like a front desk role where Nginx sits in front of the Node.js app, receiving incoming client requests, managing network traffic, and forwarding requests to the Node.js backend, improving performance, security, and scalability.

Reverse Proxy Flow:

  1. Browser connects to server IP
  2. Nginx receives the request
  3. Nginx decides if the request goes to itself as a static file (HTML, CSS, image) or to Node.js
  4. If to Node.js, Nginx forwards it internally
  5. Node.js processes it and the response goes back through Nginx to the browser

How DNS, Nginx, and Node.js Work Together

1. DNS finds the server

Looks for the domain and returns the server's IP address

2. Nginx takes over and handles the traffic

When connecting to the server, Nginx:

  • Listens for incoming connections
  • Handles many users at the same time
  • Manages security and HTTPS
  • Decides how requests are handled

3. Node.js runs the application logic

Whenever the request requires dynamic behavior (user data, authentication, database access):

  • Nginx forwards the request internally to Node.js
  • Node.js runs JavaScript on the server
  • Processes the app logic
  • Generates the dynamic response (HTML or JSON)

Complete Flow:

  1. User types example.com
  2. DNS returns the server IP
  3. Browser connects to the server
  4. Nginx receives the request
  5. Nginx serves static content or forwards to Node.js
  6. Node.js processes logic and returns a response
  7. Finally, Nginx sends the response back to the browser