Skip to main content
In this lesson you’ll learn the essentials to install and configure Nginx across common platforms, manage its service lifecycle, and host a simple static website. We’ll also review the nginx.conf layout and show how to secure your site with a firewall. What you will cover:
  • What package managers are and how they differ across platforms
  • Installing Nginx on Ubuntu, CentOS/RHEL, macOS, and Windows
  • Managing the Nginx service (status, start, stop, restart, reload)
  • The structure of nginx.conf and the common include patterns (sites-available / sites-enabled)
  • Creating server blocks (virtual hosts) to host static content
  • Allowing HTTP/HTTPS through UFW (or platform equivalents)

Package managers — quick overview

Package managers are tools that simplify installing, upgrading, configuring, and removing software by handling repositories, dependency resolution, and binary distribution. Common examples: These commands are a starting point — some distributions may require enabling repositories (e.g., EPEL for older CentOS versions) or following distro-specific install notes.

Installing Nginx — examples by OS

Ubuntu / Debian (APT)
CentOS / RHEL / Fedora (yum / dnf)
macOS (Homebrew)
Windows (Chocolatey / winget)

Managing the Nginx service

Use the native service manager for your OS. Common commands: Always test configuration before reload:

Nginx configuration layout (nginx.conf, server blocks, and includes)

Nginx uses a hierarchical configuration system with global directives, the events block, the http block, and inside http one or more server blocks that contain location blocks. Debian-style layouts commonly separate sites into sites-available and sites-enabled and use include directives to load them. Example minimal nginx.conf skeleton:
Common patterns:
  • include /etc/nginx/conf.d/*.conf; for packaged configs
  • sites-available + sites-enabled where sites-enabled contains symlinks to active configs
  • Use nginx -t to validate config syntax and systemctl reload nginx to apply changes without dropping connections
A presentation slide titled "Objectives" showing a numbered list. It outlines learning about package managers, installing Nginx on multiple OSes, managing Nginx services, and configuring nginx.conf.

Host a simple static website (server block / virtual host)

  1. Create the site directory and a simple index file (example for Ubuntu/Debian):
  1. Create a server block file (e.g., /etc/nginx/sites-available/example.com) and add the server block shown earlier.
  2. Enable the site (Debian/Ubuntu):
  1. Verify by visiting http://<SERVER_IP>/ or http://example.com if DNS points to your server.
Ports:
  • HTTP — port 80
  • HTTPS — port 443 (requires TLS certificate; consider Let’s Encrypt for free certs)

Firewall (UFW example)

On Ubuntu systems using UFW:
Be careful with firewall and SSH changes on remote servers; confirm you have another active session or console access before applying strict rules.
When managing services or editing system configuration you will typically need elevated privileges (for example, using sudo). If you are working on a remote server, be careful when changing firewall rules or SSH configuration so you don’t lock yourself out.

Summary and next steps

  • Use your OS package manager to install Nginx and learn the service manager commands for start/stop/reload.
  • Use nginx -t to test changes and systemctl reload nginx (or the OS equivalent) to apply them safely.
  • Structure sites with separate server blocks and leverage sites-available / sites-enabled on Debian-style systems.
  • Open the appropriate firewall ports and obtain TLS certificates for HTTPS.
Further reading and references:

Watch Video