In this article, we will have explained the necessary steps to install and setup Nginx on Ubuntu 20.04. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Nginx pronounced “engine x” is high performance light-weight HTTP and reverse proxy web server capable of handling large websites. It can be used as a standalone web server, load balancer, content cache, and reverse proxy for HTTP and non-HTTP servers.
Install Nginx on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install Nginx.
Nginx is available in the Ubuntu 20.04 repositories by default, so you can install Nginx directly using the
sudo apt install nginx
Once installed, check to see if the Nginx service is running:
sudo service nginx status
Step 3. Configure Firewall.
Now you can set up Uncomplicated Firewall (UFW) with Nginx to allow public access on default web ports for HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
Now check the firewall status:
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx Full ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx Full (v6) ALLOW Anywhere (v6)
Step 4. Nginx Configuration File’s Structure.
- Nginx configuration files are stored in the
- The main Nginx configuration file is
- Server block (vhost) configuration files are stored in
/etc/nginx/sites-availabledirectory. The configuration files found in this directory are used by Nginx only when linked to the
- To activate a server blocks create a symlink (a pointer) from the configuration file in a
sites-availabledirectory to the
- To write more maintainable code, it’s a good idea to follow a standard naming convention. For example, if your domain name is
mydomain.comthen the configuration file should be named
/etc/nginx/snippetsdirectory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks.
- Nginx log files (
error.log) are located in the
/var/log/nginx/directory. It is recommended to have a different
errorlog files for each server block.
Step 5. Accessing the Nginx.
Now, you can test your Nginx installation, by opening http://YOUR_IP_ADDRESS or http://YOUR_DOMAIN in your web browser. You should see the default Nginx welcome page.
That’s all you need to do to install Nginx on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. Don’t forget to share your valuable queries/suggestions in the below comment box & also drop your worthwhile feedback.