Nginx (say it like “engine-x”) is a popular web server and reverse proxy. Think of it as a front desk for your website.
Visitors knock on ports 80 (HTTP) or 443 (HTTPS). Nginx can:
Serve files — HTML, CSS, images from a folder on the server.
Proxy to an app — forward the request to Node.js, Express, or another backend on a private port.
Handle TLS — talk HTTPS to the browser while the app stays on plain HTTP inside the server (common pattern).
Beginner tip.
You do not write Nginx in JavaScript. You edit a config file, test it, and reload the service.
Why it matters
In Simple Words
What problem does it solve?
On Linux, binding to port 80 often needs special privileges. Running Node with sudo forever is awkward. Nginx listens on 80/443 for you, then quietly talks to your app on something like http://127.0.0.1:3000.
Is Nginx the same as Node?
No. Node runs your JavaScript app. Nginx is a separate program that can stand in front of that app (or serve static files alone).
When should a beginner use it?
After you can open a demo site on an EC2 instance (for example Node on EC2 or Express on EC2). Then learn the reverse proxy setup so the public URL no longer needs a weird port or sudo on Node.
A tiny traffic picture
Visitor → Nginx (80/443) → your app on localhost:3000 → response back through Nginx. If you use an Application Load Balancer instead, the ALB is the public door and Nginx may not be needed on the instance.
One virtual host: listen port, server name, locations
location { }
Rules for a URL path (serve files or proxy)
root
Folder on disk for static files
proxy_pass
Forward the request to another HTTP server (your app)
reload
Apply a new config without a hard stop (nginx -s reload or systemctl reload nginx)
reverse proxy
Nginx faces the internet; the app stays private behind it
Checklist
What You Need First
Before you install Nginx on a server:
A Linux server you can SSH into (this site’s guides often use Amazon EC2).
An app already answering on a high port (for reverse proxy), or a folder of static files to serve.
Security group / firewall rules that allow inbound 80 (and later 443).
Big picture
Where Nginx Fits
Three common beginner paths on this site:
Path 1 — Serve Static Files
Nginx alone can host a simple site from a directory (HTML/CSS/JS).
Install Nginx on the server.
Point a location /root at your files.
Reload Nginx and open the public IP on port 80.
How It Works
No Node process is required for a pure static folder.
Good for landing pages and simple brochure sites.
For a React SPA build, you often still need a fallback to index.html for client routes.
Path 2 — Reverse Proxy to Node / Express
The path most CodeToFun EC2 deploy guides lead to next.
Keep Node listening on 3000 (or another high port) with PM2.
Put Nginx on 80 with proxy_pass http://127.0.0.1:3000;.
Visitors use http://your-ip/ with no port suffix.
Hands-on next.
Follow the step-by-step Nginx reverse proxy guide for install, config, test, and common fixes.
Path 3 — Use an Application Load Balancer
On AWS you can put an ALB in front of EC2 instead of (or as well as) Nginx.
ALB terminates public HTTP/HTTPS and health-checks your instances.
Useful when you scale beyond one server.
Single-instance demos often start with Nginx on the box, then move to ALB later.
Avoid these
Common Beginner Mistakes
Editing config but never reloading
Nginx keeps the old settings until you reload or restart the service.
Proxying to a dead app port
If Node is not listening on 3000, Nginx returns 502. Check PM2 first.
Forgetting security group port 80
SSH works on 22, but browsers need 80/443 open on the instance.
Thinking Nginx replaces Express
Nginx forwards HTTP. Your routes, templates, and APIs still live in the app.
Skipping a config test
Run sudo nginx -t before reload so a typo does not take the site down.
Mixing ALB and Nginx without a plan
Either can be the public door. Decide which one visitors hit first.
Remember
Key Takeaways
Nginx is a front desk for static files and reverse proxying.
Config files, not app code, control listen ports and proxy_pass.
Reverse proxy lets Node stay on a high port while visitors use 80/443.
Test with nginx -t, then reload.
One line: Nginx faces the internet; your app (or static folder) stays behind it.
Frequently Asked Questions
Nginx is a fast open-source program that can serve website files and sit in front of your app as a reverse proxy so visitors talk to Nginx on ports 80 or 443 while your app listens on a private port.
No. You configure Nginx with text files. Your app can still be Node, Express, PHP, or static HTML. Nginx forwards or serves requests; it does not replace your application code.
Not for a first demo. Many teams later put Nginx (or a load balancer) in front so Node does not bind to privileged ports 80/443, and so TLS and static files can be handled at the edge of the server.
A reverse proxy receives the visitor request, then asks your backend for the response and sends it back. The visitor only sees Nginx. See the Nginx reverse proxy guide for a hands-on setup.
No. An ALB is a managed AWS network service. Nginx runs as software on a server (for example an EC2 instance). Both can distribute or forward traffic, but they live in different places.
The open-source Nginx web server is free to use. Check the official nginx.org site for docs and packaging. Commercial products from the same family exist separately.