How do I install NGINX on Ubuntu 22.04?

In today’s digital world, having a fast website is essential. NGINX stands out as a high-performance web server offering exceptional speed. If you’re using Ubuntu and looking to install NGINX, you’ve come to the right place. In this article, we’ll look at how to install NGINX on Ubuntu 22.04.

Environmental preparation

Before getting to the heart of the matter, the first crucial step is to prepare your Ubuntu 22.04 system environment.

This is the foundation on which NGINX will operate. Make sure your system is up to date by executing the following commands in the terminal:

sudo apt update && sudo apt upgrade

This command updates the list of available packages and upgrades all packages on your system to the latest versions.

Also make sure your system has all the necessary tools installed. If not, install them using the following command:

sudo apt install curl gnupg2 ca-certificates lsb-release

By installing these dependencies, you ensure a smooth and seamless installation of NGINX on Ubuntu.

Install NGINX

Having prepared your system environment, let’s move on to the main step: installing NGINX on Ubuntu 22.04.

The procedure is simple and straightforward. Follow the steps below for a successful installation.

Type the following command in the terminal and press Enter :

sudo apt install nginx

This command requires administrator rights to install the NGINX package on your system.

See also: How do I install phpMyAdmin on Ubuntu 22.04?

Starting and activating the NGINX service

Now that NGINX is installed on your Ubuntu 22.04 system, it’s essential to ensure that the service is active and working properly.

Here’s how to start and activate the NGINX service.

To start the NGINX service, open the terminal and run the following command:

sudo systemctl start nginx

This command starts the NGINX service, enabling your web server to begin serving web pages.

To ensure that NGINX starts automatically each time the system is booted, use the following command:

sudo systemctl enable nginx

By activating NGINX, you ensure that it’s always up and running whenever your system is operational, guaranteeing constant availability of your website.

To confirm that the NGINX service is active and running, run this command:

sudo systemctl status nginx

A positive response indicates that NGINX is working correctly.

How do I install NGINX on Ubuntu 22.04?

You should see a status indicating that the service is active and running.

UFW firewall configuration

Once NGINX has been installed and activated on your Ubuntu 22.04 system, it’s essential to configure the UFW (Uncomplicated Firewall) correctly to ensure optimum security and functionality of your web server.

Here’s how to configure the UFW firewall.

If UFW is not already installed on your system, install it with the following command:

sudo apt install ufw

Activate UFW by typing the following command in the terminal:

sudo ufw enable

Allow traffic on ports 80 (HTTP) and 443 (HTTPS) to access the NGINX web server. Run the following commands:

sudo ufw allow 'Nginx Full'
sudo ufw reload

To check that the rules are correctly defined, use the command :

sudo ufw status

The result is :

Make sure traffic is allowed on ports 80 and 443.

Check the available ufw application profiles:

sudo ufw app list

The result is :

Testing NGINX Configuration on Ubuntu

After configuring UFW, make sure you can access the NGINX home page in your web browser by navigating to the IP address of your server:


Or, try accessing localhost:


The default NGINX landing page should appear if everything has been configured correctly.

How do I install NGINX on Ubuntu 22.04?


By following these steps, you’ve learned how to install NGINX on Ubuntu. Make sure you configure the server to your specific needs and regularly check for security and performance updates for NGINX.

To find out more about Ubuntu and NGINX, take a look at the official NGINX and Ubuntu documentation. By mastering these tools, you’ll enhance the security, performance and reliability of your web deployments.


How can I check which version of NGINX is installed on my system?

Use the following command to check the NGINX version:

nginx -v

How can I stop or restart the NGINX service?

To stop NGINX, use the command :

sudo systemctl stop nginx

To restart NGINX, use the command :

sudo systemctl restart nginx

How to troubleshoot NGINX configuration errors?

Check the syntax of your configuration file with :

sudo nginx -t

See also the NGINX error logs for details of specific problems:

sudo tail /var/log/nginx/error.log

How do I access NGINX log files?
NGINX log files are generally located in /var/log/nginx/.

Use cat or tail to display the log files:

sudo tail /var/log/nginx/access.log
sudo tail /var/log/nginx/error.log

How do I disable NGINX autostart?
Use the following command to disable NGINX autostart:

sudo systemctl disable nginx

NGINX won’t start, what can I do?

Check NGINX service status and error messages with :

sudo systemctl status nginx
sudo journalctl -xe | grep nginx

How do I configure SSL for NGINX on Ubuntu 22.04?

You can use Let’s Encrypt to obtain a free SSL certificate and configure NGINX to use this SSL certificate. See the official Let’s Encrypt documentation for detailed instructions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.