TechWhale

Back

How to upgrade old version of Nginx on Ubuntu 22.04How to upgrade old version of Nginx on Ubuntu 22.04

Nginx is a powerful web server, load balancer, and reverse proxy that is used by some of the most popular websites in the world. It can help improve the performance and security of your web applications, and this guide will show you how to install the latest version of Nginx on Ubuntu 22.04.

To install Nginx, you need to follow these steps:

  1. Log in as root To proceed with the installation of Nginx, you need to be logged in as root. If you are not already logged in as root, you can switch to the root user using the following command:
$ sudo -i
bash
  1. Update package list The next step is to update the package list using the following command:
# apt update
bash
  1. Install required packages Install the required packages to your system using the following command:
# apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y
bash
  1. Import the Nginx signing key Import the Nginx signing key using the following command:
# wget -O- <https://nginx.org/keys/nginx_signing.key> | gpg --dearmor \\
    | tee /etc/apt/trusted.gpg.d/nginx.gpg > /dev/null
bash
  1. Verify the key Verify that the downloaded file contains the proper key using the following command:
# gpg --dry-run --quiet --import --import-options import-show /etc/apt/trusted.gpg.d/nginx.gpg
bash
  1. Set up the apt repository Set up the apt repository for stable Nginx packages using the following command:
# echo "deb <http://nginx.org/packages/ubuntu> `lsb_release -cs` nginx" \\
    | tee /etc/apt/sources.list.d/nginx.list
bash
  1. Update repository information Update the repository information using the following command:
# apt update
bash
  1. Remove existing Nginx installations Remove all existing Nginx installations using the following command. (This step can be skipped on new systems.)
# apt purge nginx nginx-common nginx-full nginx-core
bash
  1. Install Nginx Install Nginx using the following command:
# apt install nginx
bash
  1. Verify the installation Verify the installation and Nginx version using the following command:
# nginx -v
bash
  1. Enable the Nginx service Enable the Nginx service using the following command:
# systemctl enable nginx
bash
  1. Start Nginx Start Nginx using the following command:
# systemctl start nginx
bash
  1. Modify the default configuration The default configuration when installing Nginx through the Nginx repository differs from the default configuration when installing Nginx through the Ubuntu repository. We will modify a few things to achieve this. First, create additional directories using the following command:
# mkdir /etc/nginx/{modules-available,modules-enabled,sites-available,sites-enabled,snippets}
bash
  1. Edit the nginx.conf file Edit the nginx.conf file using the following command:
  1. Check the configuration Check the configuration using the following command:
# nginx -t
bash
  1. Restart Nginx Restart Nginx using the following command:
# systemctl restart nginx
bash
  1. Test Nginx Test if Nginx is responding using the curl command:
# curl localhost
bash

It is important to note that this tutorial assumes you are using Ubuntu 22.04. If you are using a different version of Ubuntu or a different operating system, the commands may be different. Also, make sure you have appropriate permissions before running commands.

How to upgrade old version of Nginx on Ubuntu 22.04
https://techwhale.in/upgrade-old-version-of-nginx-on-ubuntu-2204/
Author Mayur Chavhan
Published at July 26, 2023

Related posts