In this tutorial, we learn the simple commands to install Nginx on Ubuntu 22.04 Jammy JelyFish LTS Linux using the command terminal.

Apart from using as a Web server, it is also used as a proxy, cache, and load-balancing server. To install it, you just need a Linux server such as Ubuntu 22.04 and sudo user rights along with the Internet connection.

Steps to install Nginx on Ubuntu 22.04 LTS

1. Update Ubuntu 22.04

Start with updating the system which we’ll refresh the APT package manager index cache. It is important when we install some applications on Ubuntu using the default package manager.

 

sudo apt update

2. Install Nginx on Ubuntu 22.04

Nginx is a popular open-source software, hence available to install using the default system repository of Ubuntu 22.04. So, in your command terminal just run the following given command.

sudo apt install nginx

3. Start, Restart or Stop the Nginx service

Once the installation is completed, nothing else we need to do. However, to confirm it is on our system running fine without generating any errors run the command given here.

For getting version details:

nginx -v

For Checking the status of the Nginx service, we can use:

sudo systemctl status nginx --no-pager -l

If the service is not running, then we can start it using:

sudo systemctl start nginx

Whereas, in the future, if you want to stop or restart the Nginx then the commands to use are:

To restart:

sudo systemctl restart nginx

To Stop:

sudo systemctl stop nginx

4. Open Firewall for Nginx

If you are relying on the Ubuntu system firewall and it is active, then we have to open port 80 for the HTTP connection and 443 for the HTTPS connection. You can use the given command for that:

sudo ufw allow 'Nginx Full'

Whereas those who are using some cloud hosting service such as Amazon Lightsail, need to manually open the ports in their service provider’s firewall.

5. Check the Test page

To confirm, the Nginx is properly delivering the test page over HTTP, open your browser and type: http://127.0.0.1 or http://your-server-ip-address