This is a quick reference for installing Nginx on Ubuntu 20.04. The same process should work on older Ubuntu versions from at least 16.04 onwards.
Install Nginx package
sudo apt update && sudo apt install -y nginx
Disable Apache if installed
If you have Apache installed (check with
apache2 --version), you may want to disable it. Apache is often automatically installed when you install PHP.
sudo systemctl stop apache2
Start Nginx service
sudo systemctl start nginx sudo systemctl status nginx
The output of the Nginx service should show
Active: active (running)
Check Nginx has been installed correctly
The default Nginx configuration (
/etc/nginx/sites-enabled/default) should have Nginx listening on port 80 and serving
So if you visit localhost, you should see either the default Nginx landing page or the Apache landing page if you previously had Apache installed. Either way, seeing any of these pages means Nginx is running properly.
Nginx landing page
Apache landing page
Setup server blocks
Now that Nginx is running properly, you'll want to create server blocks to host multiple domains on your server.