Deploy Nginx Today: Complete Step-by-Step Tutorial

Learn how to easily set up and run NGINX on your Linux server with this beginner-friendly guide.

Getting Started with Web Servers

Understanding NGINX

NGINX (pronounced "engine-x") is a powerful and very popular web server software used by millions of websites around the world. At its core, its main job is to take requests from users like when you type a website address into your browser and send back the correct web page so you can see it. It is famous for being extremely fast and reliable, even when a website gets thousands of visitors at the exact same time.

Besides just serving regular web pages, NGINX can do a lot of other helpful tasks to keep a system healthy. For example, it can act as a "traffic cop" (known as a reverse proxy) that stands in front of several other servers. It smoothly directs visitor traffic to different machines so that no single server gets overworked. This makes websites load faster and stops them from crashing during very busy moments.

Another great thing about NGINX is that it is lightweight, meaning it uses very little of your computer's memory and processing power. Because it is so efficient, many companies use it to quickly deliver heavy files like images and videos. Whether you are building a small personal blog or managing a massive online store, NGINX is a fantastic tool to keep everything running smoothly.

Major Prerequisites

  • A computer or cloud server running a Linux operating system (like Ubuntu, CentOS, or Red Hat Enterprise Linux).
  • Access to the server's command line or terminal.
  • A user account with sudo (administrator) privileges to install new software.
  • An active internet connection to download the required packages.

Step-by-Step Installation

For Ubuntu (Versions 22.04, 24.04, 26.04)

1. Install Prerequisites

Run this command to install the tools needed to download and verify the NGINX software safely:

Bash
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

2. Import the NGINX Security Key

This step downloads the official NGINX security key so your system knows the software is genuine:

Bash
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Verify that the key is correct by running:

Bash
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

3. Add the NGINX Repository

Tell your system where to find the official NGINX software:

Bash
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
https://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

4. Set Up Repository Pinning

This command makes sure your system prefers the official NGINX packages over older versions:

Bash
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

5. Install NGINX

Finally, update your system's package list and install the web server:

Bash
sudo apt update
sudo apt install nginx

For RHEL & Derivatives (CentOS, Rocky Linux, AlmaLinux)

1. Install Prerequisites

Install the necessary package management tools:

Bash
sudo yum install yum-utils

2. Set Up the YUM Repository

Create a configuration file to tell your system where to download NGINX:

Bash
sudo nano /etc/yum.repos.d/nginx.repo

Paste the following exact contents into the file, then save and exit:

Ini, TOML
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

3. Install NGINX

Run the installation command. When it asks you to accept the security key (GPG key), type y to confirm:

Bash
sudo yum install nginx

Final Thoughts

Congratulations, you have successfully prepared your Linux system and installed one of the most powerful web servers available today.

  • Learned the basics of what NGINX is and how it handles website traffic efficiently.
  • Installed the necessary prerequisite tools and security keys on your server.
  • Added the official NGINX software repository to your system's package manager.
  • Successfully installed the NGINX web server software using step-by-step terminal commands.

You are now completely ready to start configuring your server and hosting your own websites.