Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server and reverse proxy. It handles a large number of concurrent connections with a smaller memory footprint per connection compared to Apache, making it a reliable foundation for web applications and APIs.
This guide covers two methods to install Nginx on Ubuntu 16.04: from the default Ubuntu repositories, which is the simpler option, and from the official Nginx stable PPA, which provides the latest release. We also cover UFW firewall setup, systemctl service commands, and the Nginx directory layout.
Prerequisite: You need sudo access. Make sure no other service is running on port 80 or 443 before starting.
Install Nginx from the Ubuntu 16.04 default repositories:
bashsudo apt updatesudo apt install nginx
The Nginx service starts automatically after installation. Verify it is running:
bashsudo systemctl status nginx
Check the installed version:
bashsudo nginx -v
The Ubuntu 16.04 default repositories provide Nginx 1.10.3.
Open the firewall. The Nginx Full UFW profile opens both HTTP (port 80) and HTTPS (port 443) in one command:
bashsudo ufw allow 'Nginx Full'
Run sudo ufw status to verify. Visit http://YOUR_SERVER_IP in a browser. The default Nginx welcome page confirms the server is installed and reachable.
The Ubuntu 16.04 default repositories often lag behind the current Nginx stable release. If you need the latest version, add the official Nginx stable PPA, which is maintained directly by the Nginx project team. It gives you access to newer security patches, performance improvements, and HTTP/2 refinements that are not backported to the Ubuntu-packaged version.
Add the PPA and install Nginx:
bashsudo apt install software-properties-commonsudo add-apt-repository ppa:nginx/stablesudo apt updatesudo apt install nginx
Verify the installed version:
bashsudo nginx -v
The Nginx PPA version at the time of writing is 1.12.2, significantly more current than the 1.10.3 version in the Ubuntu repos. The PPA updates automatically when new Nginx stable releases are published, so future installs will always pull the latest.
Control the Nginx service with standard systemctl commands:
bashsudo systemctl stop nginx # Stop the servicesudo systemctl start nginx # Start the servicesudo systemctl restart nginx # Restart (briefly drops connections)sudo systemctl reload nginx # Reload config without dropping connectionssudo systemctl disable nginx # Disable auto-start at bootsudo systemctl enable nginx # Enable auto-start at boot
Use reload after configuration changes. Reserve restart for cases where a full process restart is required, such as installing new Nginx modules.
Nginx config directory layout:
/etc/nginx/nginx.conf — main configuration file (global settings)/etc/nginx/sites-available/ — server block configs for each domain (inactive until symlinked)/etc/nginx/sites-enabled/ — symlinks to active server block files/etc/nginx/snippets/ — reusable config fragments for SSL or other shared settings/var/log/nginx/ — access.log and error.log (create a separate pair per domain)Common document root locations: /var/www/example.com, /home/user/example.com, and /opt/example.com.
Nginx is now installed and running on your Ubuntu 16.04 server. To enable HTTPS, follow the guide on securing Nginx with a free Let’s Encrypt SSL certificate. Leave a comment below if you run into any issues.