Skip to main content
This guide gives a concise, practical overview of NGINX configuration and the structure of the primary configuration file, nginx.conf. It explains the typical file layout, key configuration blocks, example snippets, and common commands you’ll use when managing NGINX. This is ideal for beginners and engineers who need a quick reference while editing configs.
On most Linux distributions nginx.conf lives at /etc/nginx/nginx.conf. You can confirm this with nginx -V which prints the configured paths.
You’ll typically see this high-level structure in nginx.conf:
  • Global settings — server-wide options (user, worker counts, pid file, etc.)
  • events block — connection and event model settings
  • http block — HTTP-level configuration and includes for server blocks
  • server blocks — virtual hosts that define how NGINX responds to requests
Global settings apply to the whole NGINX instance: user privileges, number of worker processes, PID file, and other server-wide behaviors. Features like compression and caching are usually configured inside the http block rather than the global scope.
A slide titled "Structure of nginx.conf" showing a "Global Settings" box that "set up configurations that affect the entire Nginx server." Below are icons and labels for examples like user privileges, number of worker processes, and rate limiting settings.

events block

The events block controls how worker processes handle connections and the event model (select/epoll/kqueue). A minimal events block:
Key points:
  • worker_connections sets the max simultaneous connections each worker can handle.
  • Total theoretical concurrent connections ≈ worker_processes * worker_connections.
  • Real limits depend on OS file descriptor limits (ulimit), socket limits, and other factors — treat the formula as an approximation.
  • use is optional; NGINX auto-selects the best mechanism if you omit it (epoll on Linux, kqueue on BSD/macOS).

http block

The http block holds HTTP-specific settings: logging, compression, MIME types, keepalives, and includes for server blocks or other fragments. A practical example:
Notes:
  • Use include to keep nginx.conf concise and load site-specific files from conf.d or sites-enabled.
  • Configure gzip, caching, proxy, and upstreams in this section or in included files.

server block (virtual host)

server blocks (virtual hosts) define how NGINX responds for specific domains, IPs, or ports. You can host multiple sites on one instance by adding multiple server blocks.
A slide titled "Creating and Editing Server Blocks (Virtual Hosts)" showing four colorful browser/window icons labeled "WWW" tied by lines into a single stack of servers below, illustrating multiple virtual hosts served from one server.
NGINX chooses the matching server block using listen and server_name (or the IP) from the incoming request.
A presentation slide titled "Creating and Editing Server Blocks (Virtual Hosts)". It shows a user icon sending a "Request" arrow to the NGINX logo, with labels like "server_name" and "IP address" beneath.
Example server block:
Directive summary: Default webroots vary by distribution:
  • Debian/Ubuntu: /var/www/<site>/html
  • CentOS/Red Hat: /usr/share/nginx/html

NGINX modules

NGINX functionality is provided by modules (core HTTP module, SSL, proxy, rewrite, gzip, etc.). Which directives you can use depends on the modules compiled into your NGINX binary. Use nginx -V to see compile-time modules and options.
A presentation slide titled "Nginx Modules" showing a screenshot of the ngx_http_core_module documentation with a long list of Nginx directive names and the NGINX logo. The slide also credits KodeKloud in the corner.

Common NGINX directories and files

Typical locations and purpose: Using symbolic links in sites-enabled is a common pattern to enable/disable sites (similar in intent to Apache’s approach, but usually managed manually or with helper scripts).

Useful NGINX commands

Use the following commands when managing or troubleshooting NGINX: Always validate configuration before reloading:
Run nginx -t (or sudo nginx -t) after edits to verify syntax and detect errors before reloading or restarting NGINX.
Example syntax check output:
Reload vs restart:
  • nginx -s reload or sudo systemctl reload nginx — reloads config without dropping existing connections (preferred when possible).
  • sudo systemctl restart nginx — fully restarts the service and interrupts active connections.
That wraps up this concise overview of NGINX configuration structure and common operations.

Watch Video