Skip to main content
This lesson covers the essentials for installing, configuring, and managing Nginx. You’ll learn:
  • How package managers work and which to use on common platforms.
  • How to install Nginx on Ubuntu (primary), plus CentOS, macOS, and Windows.
  • How to manage Nginx as a service (status, start, stop, restart, reload).
  • How the nginx.conf file is structured and how configuration is inherited.
  • How to host a simple static website with Nginx and allow traffic via UFW.
A presentation slide titled "Objectives" listing three goals: understand package managers, install Nginx on Ubuntu/CentOS/macOS/Windows, and manage Nginx services (status, start, stop, reload, restart).

Package managers: overview and quick comparison

Package managers automate installing, upgrading, configuring, and removing software. Below are common examples and typical use cases: Use the package manager native to your OS for the smoothest installation and updates.
When choosing where to run Nginx on Windows, prefer WSL (Windows Subsystem for Linux) for a Linux-like experience and easier parity with production Linux servers.

Install Nginx — quick commands by platform

Below are concise, platform-specific instructions. These are the most common, production-friendly approaches. Ubuntu (Debian-family)
CentOS / RHEL / Fedora
macOS (Homebrew)
Windows
  • Recommended: use WSL and follow the Ubuntu instructions inside the WSL environment.
  • Alternatively, use Chocolatey:

Manage the Nginx service

You will commonly use systemctl on modern Linux systems. Here are the essential commands: Older SysV init / compatibility:
Reloading (reload) applies configuration changes without terminating worker processes; use restart when you need a full restart. Always test config before reloading: sudo nginx -t.

Understanding nginx.conf: structure and inheritance

Nginx configuration is hierarchical. The main contexts you should know:
  • Main/global context (top-level): process-wide directives (user, worker_processes, error_log).
  • events context: connection handling directives (e.g., worker_connections).
  • http context: HTTP server configuration, MIME types, logging, upstreams, and general server directives.
  • server blocks: Virtual hosts — listen addresses, server_name, SSL, access logging.
  • location blocks (inside server): How requests are routed and handled for specific URIs.
Minimal example (illustrative):
Always validate changes before reloading:

Host a static website with Nginx

Typical steps to serve a simple static site:
  1. Create the document root and a test page:
  1. Create a server block (virtual host). On Debian/Ubuntu, use sites-available and sites-enabled:
  1. Enable the site and reload:
If you use a different path or platform, adapt the file locations accordingly.

Networking basics & firewall (UFW)

Nginx commonly uses these ports: Allow HTTP/HTTPS through UFW on Ubuntu:
You can also permit only HTTP or HTTPS as needed ('Nginx HTTP' or 'Nginx Full').
Use these resources for deeper configuration examples, SSL/TLS setup, reverse proxy patterns, and performance tuning.

Watch Video