Serving Your Own Pages
The default site's configuration is in /etc/nginx/sites-available/default:
cat /etc/nginx/sites-available/default
Two lines matter most:
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
root is the folder nginx serves; a request for /about.html becomes the file /var/www/html/about.html. For a folder (/), nginx looks for the index files in that order — right now only index.nginx-debian.html, the welcome page, exists.
Put up your own page
/var/www/html belongs to root, so write into it with sudo tee (a plain sudo echo ... > file wouldn't work — the > is done by your shell, as you):
ls -l /var/www/html
echo '<h1>Hello from my server</h1>' | sudo tee /var/www/html/index.html
curl localhost
index.html comes before the welcome page in the index list, so it's served now. More pages are more files:
echo '<h1>About us</h1>' | sudo tee /var/www/html/about.html
curl localhost/about.html
When it goes wrong
| Status | Meaning |
|---|---|
200 OK | here's the page |
301 Moved Permanently | it's somewhere else (/blog → /blog/) |
403 Forbidden | it's there, but nginx may not show it |
404 Not Found | there's no such file |
curl -I localhost/missing.html # 404
echo secret | sudo tee /var/www/html/secret.html
sudo chmod 600 /var/www/html/secret.html
curl -I localhost/secret.html # 403
403 happens because nginx reads files as www-data: a file only root may read (600) is off limits. Pages need to be readable by others — chmod 644, and folders 755.
💡 Every request is written to
/var/log/nginx/access.log, and the reason for a 403 or 404 to/var/log/nginx/error.log.