Ubuntu

How to install NGINX on Ubuntu 22.04

NGINX is an open-source high performing 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 so on.

NGINX acts as a forward proxy server for email protocols (IMAP, SMTP, and POP3). Moreover, NGINX provides reverse proxy server and load balancing support for well-known computer protocols such as HTTP, TCP, and UDP servers.

NGINX is available for various Linux systems such as Debian, CentOS, RedHat Enterprise Linux (REHL), and more. This writeup acts as an installation guide of NGINX on Ubuntu 22.04.

How to install NGINX on Ubuntu 22.04

This section enlists various steps to install NGINX on Ubuntu 22.04 from the official repository of Ubuntu 22.04.

Step 1: Update the system’s packages by issuing the following command:

$ sudo apt update

Step 2: Once the system’s packages are updated, you can install NGINX with the help of the following command:

$ sudo apt install nginx

Step 3: Verify the installation by checking version of NGINX:

$ nginx -v

Get the status of the NGINX service as follows:

$ sudo systemctl status nginx

You can enable the NGINX service to start the service at the startup of the system automatically:

$ sudo systemctl enable nginx

Moreover, you can restart and start the NGINX service by using the following commands:

$ sudo systemctl restart nginx
$ sudo systemctl start nginx

Step 4: Now, you need to configure the firewall to allow traffic on HTTP port 80 and HTTP port 443. You can use the following command to get the traffic on both ports for NGINX:

$ sudo ufw allow 'Nginx full'

Reload the firewall to adapt to the changes:

$ sudo ufw reload

Step 5: Once the NGINX is installed and configured properly. You can use the following address in the browser to check whether NGINX is running or not:

http://127.0.0.1

Or you can get the result on the terminal via the following command:

$ curl -i 127.0.0.1

The output shows the HTML code of the welcome page of NGINX.

How to remove NGINX from Ubuntu 22.04

NGINX server can be removed from Ubuntu 22.04 with the help of the following command. This command removes the NGINX server alongside its dependencies from Ubuntu 22.04:

$ sudo apt autoremove nginx --purge

Conclusion

NGINX is the web server that provides various services such as web proxy server, email proxy server, load balancing, media streaming, etc. NGINX server is available on the official repository of Ubuntu 22.04; therefore, it can be installed using a simple set of commands. Alongside the installation, you have learned the basic configuration of the NGINX server as well.

About the author

Adnan Shabbir