Configuration Structure

Harry · 12 Sep 2026 · 11 views

The Master File

/etc/nginx/nginx.conf opens with a top-level install (user, worker_processes), then contexts:

user www-data;
worker_processes auto;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    ...
}

Contexts Are Nested Boxes

http {           # global: applies to all sites
    server {     # one virtual host
        listen 80;
        server_name example.com;
        location / {          # path-specific rules
            root /var/www/example;
            index index.html;
        }
        location /api/ {
            proxy_pass http://127.0.0.1:8080;
        }
    }
}

Inner contexts inherit and override outer settings. include splits config across files to stay organized.

Sites Versus Conf.d

  • sites-available / sites-enabled - the Ubuntu convention for per-site servers.
  • conf.d/*.conf - one file per extra config (security headers, proxy params).
  • Everything is a plain-text file - there is no .htaccess-style per-directory config.

Reloading Safely

sudo nginx -t && sudo systemctl reload nginx

Key Points

  • Think in contexts: http > server > location.
  • Use include files to keep large configs maintainable.
  • Validate with nginx -t on every change.
Share this post:

Comments (0)

Please login or register to comment.