How to Install Nginx on Ubuntu 22.04

 

Install Nginx on Ubuntu 22.04

In this article, we will have explained the necessary steps to install Nginx on Ubuntu 22.04 LTS. 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 is open-source software and is used as a web server. Nginx is well known for its performance and effective results as compared to Apache or other web servers. NGINX serves multiple purposes such as email proxy server, reverse and forward proxy serving, media streaming, load balancing, and many more

Prerequisite:

  • Operating System with Ubuntu 22.04
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install Nginx on Ubuntu 22.04 LTS

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
sudo apt install software-properties-common dirmngr apt-transport-https

Step 2. Install Nginx on Ubuntu Linux.

Installing the Nginx on your Ubuntu 22.04 Jammy Jellyfish system is straightforward, Now, execute the following command on the command line or terminal to download and install the Nginx web server on the Ubuntu system:

sudo apt install nginx

After you have successfully installed Nginx, you now need to enable, start and check the status it using the following command:

sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx

Verify the installation by checking the version of Nginx:

nginx -v

Step 3. Configure UFW Firewall.

Since the UFW firewall runs by default on Ubuntu 22.04, you can easily enable the connection using the following command:

sudo ufw allow 'Nginx FULL'
sudo ufw enable

Check the status of UFW:

sudo ufw status

Step 4. Nginx Configuration File’s Structure.

  • Nginx configuration files are stored in the /etc/nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Server block (vhost) configuration files are stored in /etc/nginx/sites-available directory. The configuration files found in this directory are used by Nginx only when linked to the /etc/nginx/sites-enabled directory.
  • To activate a server blocks create a symlink (a pointer) from the configuration file in a sites-available directory to the sites-enabled directory.
  • To write more maintainable code, it’s a good idea to follow a standard naming convention. For example, if your domain name is mydomain.com then the configuration file should be named /etc/nginx/sites-available/mydomain.com.conf.
  • The /etc/nginx/snippets the directory 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 (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have a different access and error log files for each server block.

Step 5. Accessing the Nginx Web UI.

Once the Nginx is installed and set up properly. You can use the following address in the browser to check whether Nginx is running or not:

http://your-ip-address

Install Nginx on Ubuntu 22.04 LTS

That’s all you need to do to install Nginx on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installation of the Nginx web server, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.