Nginx configuration looks intimidating at first, but it follows a simple structure. Here's what a beginner needs to know.

Where config lives

  • /etc/nginx/nginx.conf — the main file.
  • /etc/nginx/sites-available/ — one file per site.
  • /etc/nginx/sites-enabled/ — symlinks to the sites you've turned on.

A minimal server block

server {
    listen 80;
    server_name example.com;
    root /var/www/example.com;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Enable and reload

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t          # always test first
sudo systemctl reload nginx

The golden rule

Always run nginx -t before reloading — it catches syntax errors so you don't take your sites down. Once you understand server blocks and location directives, everything else builds on these basics.