Install Nginx on Ubuntu 20.04

Nginx is an open-source web server that serves web content to a clients. It can also be used as a reverse proxy, load balancer, cache server, and more.

This tutorial demonstrates how to install Nginx on Ubuntu 20.04.

Install Nginx

Add the Nginx repository:

sudo add-apt-repository -y ppa:ondrej/nginx

Install Nginx:

sudo apt install -y nginx

Once installation is finished, we can check Nginx version:

nginx -v

Run the following command to enable Nginx to start on boot:

sudo systemctl enable nginx

You can check whether Nginx service is running with command:

sudo service nginx status

Also you can stop, start and restart the Nginx service:

sudo service nginx stop
sudo service nginx start
sudo service nginx restart

Testing Nginx

Get the IP address of your machine:

hostname -I

Open a web browser and type the IP address. The default Nginx welcome page will be presented as shown below:

Nginx default page on Ubuntu

Uninstall Nginx

If you decided to completely remove Nginx and related dependencies, execute the following command:

sudo apt purge --autoremove -y nginx

Disable Nginx service:

sudo systemctl disable nginx
sudo systemctl daemon-reload
sudo systemctl reset-failed

Remove GPG key and repository:

sudo rm -rf /etc/apt/trusted.gpg.d/ondrej_ubuntu_nginx.gpg
sudo rm -rf /etc/apt/sources.list.d/ondrej-ubuntu-nginx-focal.list

Leave a Comment

Your email address will not be published. Required fields are marked *