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 small memory footprint per connection, which makes it a popular choice for high-traffic sites, APIs, and microservice infrastructures.
Nginx can work as a standalone web server or as a reverse proxy in front of another application server. Compared to Apache, its event-driven, non-blocking architecture scales much better under concurrent connection load.
This guide covers how to install Nginx on Ubuntu 18.04, open the firewall with UFW, manage the service with systemctl, and understand the Nginx configuration directory structure.
<strong>Prerequisite:</strong> You need sudo access. Make sure Apache or another service is not running on port 80 or 443.
Nginx packages are available in the Ubuntu 18.04 default repositories:
bashsudo apt updatesudo apt install nginx
The Nginx service starts automatically after installation. Verify it is running:
bashsudo systemctl status nginx
The output should show Active: active (running).
Open UFW ports. Use the Nginx Full profile to open both HTTP (port 80) and HTTPS (port 443) with one command:
bashsudo ufw allow 'Nginx Full'
Verify with sudo ufw status. Visit http://YOUR_SERVER_IP in a browser — the default Nginx welcome page confirms the server is installed and reachable.
All Nginx service operations use standard systemd commands:
| Action | Command |
|---|---|
| Stop Nginx | sudo systemctl stop nginx |
| Start Nginx | sudo systemctl start nginx |
| Restart Nginx | sudo systemctl restart nginx |
| Reload config only | sudo systemctl reload nginx |
| Disable auto-start at boot | sudo systemctl disable nginx |
| Re-enable auto-start at boot | sudo systemctl enable nginx |
Use reload when you have only changed configuration files. Reload applies the new config without dropping active connections, which is important on live servers. Use restart only when installing new Nginx modules or making changes that require a full process restart.
Understanding the Nginx directory layout is essential for managing multiple domains without creating config conflicts.
/etc/nginx/ — root directory for all Nginx configuration files/etc/nginx/nginx.conf — main configuration file; sets global settings like worker processes and connection limits/etc/nginx/sites-available/ — stores server block config files for each domain; files here are inactive until symlinked/etc/nginx/sites-enabled/ — contains symbolic links to active server block files/etc/nginx/snippets/ — reusable config fragments you can include across multiple server blocks (useful for SSL settings)/var/log/nginx/ — stores access.log and error.log; create a separate log pair for each server blockNaming convention. Name each config file after the domain it serves, for example /etc/nginx/sites-available/example.com.conf. Activate it by creating a symlink:
bashsudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/
Common document root locations include /var/www/example.com, /home/user/example.com, and /opt/example.com. Pick one location and apply it consistently across all your virtual hosts to simplify maintenance.
Nginx is now installed and running on your Ubuntu 18.04 server. To add 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.