In this tutorial, we will show you how to install Nginx on Ubuntu 20.04 LTS. For those of you who didn’t know, Nginx is a powerful web server software that can be used on your server. It is also known for its high performance and low memory usage which will allow fewer resources to be used but getting the job done efficiently. A popular setup is to use it as a proxy for Apache, which can then serve application requests.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of Nginx on a Ubuntu 20.04 (Focal Fossa) server.
Install Nginx on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following
apt commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing Nginx on Ubuntu 20.04.
Nginx is available in the default Ubuntu repositories. To install it run the following command:
sudo apt install nginx
Once the installation is completed, run the commands to enable Nginx to automatically startup when your server starts:
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
Step 3. Configuring firewall.
Meanwhile, you need to make sure that your firewall is configured to allow traffic on HTTP (80) and HTTPS (443) ports. Nginx registers itself as a service with
sudo ufw allow in "Nginx Full"
Step 4. Accessing Test the Installation.
To test Nginx setup, open your browser and browse to the server hostname or IP address and you should see the Nginx default test page as shown below:
Step 5. Nginx Configuration File’s Structure.
/var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the
/var/www/htmldirectory. This can be changed by altering Nginx configuration files.
/etc/nginx: The Nginx configuration directory. All of the Nginx configuration files reside here.
/etc/nginx/nginx.conf: The main Nginx configuration file. This can be modified to make changes to the Nginx global configuration.
/etc/nginx/sites-available/: The directory where per-site server blocks can be stored. Nginx will not use the configuration files found in this directory unless they are linked to the
sites-enableddirectory. Typically, all server block configuration is done in this directory and then enabled by linking to the other directory.
/etc/nginx/sites-enabled/: The directory where enabled per-site server blocks are stored. Typically, these are created by linking to configuration files found in the
/etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the Nginx configuration. Potentially repeatable configuration segments are good candidates for refactoring into snippets.
/var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
/var/log/nginx/error.log: Any Nginx errors will be recorded in this log.
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx web server in Ubuntu 20.04 LTS (Focal Fossa) system. For additional help or useful information, we recommend you check the official Nginx website.