CentOSLinuxTutorials

How To Install Nginx on Ubuntu 20.04 LTS

Install Nginx on Ubuntu 20.04

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 while 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 the step-by-step installation of Nginx on a Ubuntu 20.04 (Focal Fossa) server.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04 (Focal Fossa).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

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 ufw :

sudo ufw allow in "Nginx Full"

Step 4. Accessing Test the Installation.

To test the 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:

Install Nginx on Ubuntu 20.04

Step 5. Nginx Configuration File’s Structure.

Content:

  • /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/html directory. This can be changed by altering Nginx configuration files.

Server Configuration:

  • /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-enabled directory. 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 sites-available directory.
  • /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.

Server Logs:

  • /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.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button