Module 66: Web Server Configuration
What Nginx does
🏠The everyday picture
A large hotel's front desk: it greets every guest, hands out brochures itself, sends guests to the right department, keeps out people who shouldn't be there, and handles crowds smoothly, so the departments behind can focus on their work.
📘What it really is
- Nginx (pronounced "engine-x") is a fast, widely used web server. In front of an app, it:
- serves static files (HTML, CSS, JavaScript, images) very efficiently, such as your built React app;
- acts as a reverse proxy, passing other requests to your Node.js app (Lesson 3);
- handles HTTPS (Lesson 4);
- hosts several sites on one server (Lesson 2);
-
can compress responses, cache, limit request sizes and rates, and add security headers.
-
Apache is the other long-established web server (common on shared hosting, using
.htaccessfiles like your test site). Caddy is a newer, simpler option that sets up HTTPS automatically. -
Install and check:
sudo apt install nginx
systemctl status nginx
curl -I http://localhost
-
Configuration lives in
/etc/nginx/: the main filenginx.conf, and one file per site insites-available/, switched on by a link insites-enabled/. -
After every change:
sudo nginx -t(test the configuration) and, if OK,sudo systemctl reload nginx(apply without dropping connections).
🖱️Try it
Install Nginx in your lab and open its welcome page (curl http://localhost, or the lab's address in your browser). Look
at /etc/nginx/sites-available/default. Run sudo nginx -t.
✅Quick check
Name three jobs Nginx does in front of an app.
Show the answer
Any three: serving static files, reverse proxying to the app, HTTPS, hosting several sites, compression, limits, security headers.
What should you run before reloading Nginx after a change?
Show the answer
sudo nginx -t to test the configuration.
