Skip to content
Runbook

Install Nginx on Ubuntu / Debian

High-performance web server, reverse proxy, load balancer and HTTP cache.

Toolweb-serverreverse-proxyload-balancerhttpproxy

Installation

Nginx (Ubuntu repositories) · apt
sudo apt update
sudo apt install -y nginx

Verify the installation

Verify
nginx -v

Service

Start
sudo systemctl start nginx
Stop
sudo systemctl stop nginx
Status
sudo systemctl status nginx
Restart
sudo systemctl restart nginx
On boot
sudo systemctl enable nginx

Important files

TypePathDescription
config/etc/nginx/nginx.confMain configuration file.
config/etc/nginx/sites-availableAvailable site definitions; symlink into sites-enabled to activate.
data/var/www/htmlDefault document root.
log/var/log/nginxAccess (access.log) and error (error.log) logs.

Default ports

80

Command-line tools

  • nginxThe server binary; nginx -t to test, nginx -s reload to reload.

Uninstall

Uninstall
sudo apt purge -y nginx nginx-common
sudo apt autoremove -y

Good to know

  • Debian/Ubuntu use the sites-available + sites-enabled pattern; enable a site with sudo ln -s /etc/nginx/sites-available/foo /etc/nginx/sites-enabled/.
  • Always run sudo nginx -t before sudo systemctl reload nginx.
  • The default welcome page is served from /var/www/html.

Installation on Ubuntu

sudo apt install -y nginx installs Nginx and registers the nginx systemd service, started automatically on port 80. Visit http://localhost to see the default welcome page served from /var/www/html.

The sites-available pattern

Debian/Ubuntu split virtual hosts into /etc/nginx/sites-available (definitions) and /etc/nginx/sites-enabled (active symlinks). Enable a site with sudo ln -s /etc/nginx/sites-available/foo /etc/nginx/sites-enabled/, then reload.

Validate before reloading

Always run sudo nginx -t to check syntax, then apply with sudo systemctl reload nginx (a reload re-reads the config without dropping live connections).