Install and run Nginx, understand how its config is structured into http, server, and location blocks, and learn the test-then-reload workflow that applies changes with zero downtime.
Nginx is a web server: a program that listens for HTTP requests and responds — by serving files, or by passing the request to your app. Install it from your package manager and start it as a service. Once running, opening the server in a browser shows the default welcome page, which means it is listening. Pick your OS — the commands switch to match.
Debian / Ubuntu
sudo apt update && sudo apt install nginxStart now and on every boot, then confirm it answers:
sudo systemctl enable --now nginxcurl http://localhost # -> the default Nginx welcome HTMLNginx config is a tree of blocks. The top-level http block holds all web settings; inside it, each server block is one site (which ports and domain names it answers); inside that, location blocks decide what to do with different URL paths. The main file is /etc/nginx/nginx.conf, but you normally add one file per site under /etc/nginx/conf.d/ (or sites-available on Debian). Here is the smallest useful server.
# /etc/nginx/conf.d/example.conf
server {
listen 80; # the port this site answers on
server_name example.com; # the domain it matches
location / { # how to handle requests to "/..."
default_type text/plain;
return 200 "Hello from Nginx\n";
}
}Knowing the config is one thing; writing the file is another. the command below opens the file, creating it if it does not exist yet, so you can paste your server block in. To paste into a WSL or Linux terminal, right-click or press Ctrl+Shift+V. Save with Ctrl+O then Enter, and exit with Ctrl+X.
sudo nano /etc/nginx/conf.d/example.confA typo in a config can take your site down, so Nginx gives you a dry run: nginx -t parses every file and reports errors without applying anything. Only reload once it passes. reload swaps in the new config gracefully — existing connections finish on the old config while new ones use the new one, so there is no dropped request. Make this your habit: edit, test, reload.
1. Check the config is valid BEFORE applying it:
sudo nginx -t2. Apply it gracefully (no dropped connections):
sudo systemctl reload nginx