NGINX is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It’s efficient, versatile, and more resource-friendly than Apache. It is a free and open-source software for reverse proxying, load balancer, web serving, media streaming, etc. It is pronounced as “Engine X”, by eliminating the letter “e” from this, the name becomes “Nginx”.

It is Open Source and available in two versions:

  • Mainline – Includes the latest features and bug fixes and is always up to date. It is reliable, but it may include some experimental modules, and it may also have some number of new bugs.
  • Stable – Doesn’t include all of the latest features, but has critical bug fixes that are always backported to the mainline version. We recommend the stable version for production servers.

Nginx server versions, Release Dates and Release branch:

VersionRelease DateRelease
1.2523 May 2023Mainline
1.2411 Apr 2023Stable
Nginx release dates
Install Nginx latest version
Install-Nginx-latest-version

Steps to install latest NGINX on Linux

Prerequisites:

  • sudo privileges.
  • Stable internet connection.
  • Disable SELinux and Firewall.

1. Installation on Red Hat and its derivatives:

Steps to install latest Nginx on Red Hat Enterprise Linux, CentOS, Oracle Linux, Rocky Linux, AlmaLinux and Amazon Linux 2 or Amazon Linux 2023.

Install the prerequisites:

# yum install yum-utils -y

Set up Nginx yum repository for CentOS, Oracle Linux, Rocky Linux or AlmaLinux:

# tee /etc/yum.repos.d/nginx.repo<<EOM
[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
 
[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOM

Set up Nginx yum repository for Red Hat Enterprise Linux:

# tee /etc/yum.repos.d/nginx.repo<<EOM
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/rhel/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
 
[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/rhel/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOM

Set up Nginx yum repository for Amazon Linux 2:

# tee /etc/yum.repos.d/nginx.repo<<EOM
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/amzn2/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
priority=9
 
[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/amzn2/\$releasever/\$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
priority=9
EOM

Set up Nginx yum repository for Amazon Linux 2023:

# tee /etc/yum.repos.d/nginx.repo<<EOM
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/amzn/2023/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
priority=9

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/amzn/2023/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
priority=9
EOM 

By default, the repository for stable Nginx packages is used. If you would like to use mainline Nginx packages, run the following command (Optional):

# yum-config-manager --enable nginx-mainline

To install Nginx, run the following command:

# yum install nginx -y

2. Installation on Debian and its derivatives::

Steps to install latest Nginx on Debian and Ubuntu

Install the prerequisites:

# apt install curl gnupg2 ca-certificates lsb-release -y

Set up Nginx apt repository for Ubuntu:

# apt install ubuntu-keyring -y

Import an official Nginx signing key:

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

Verify that the downloaded file contains the proper key:

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

Now set up the apt repository for stable Nginx packages:

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

If you would like to use mainline Nginx packages (Optional):

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

Set up Nginx apt repository for Debian:

# apt install debian-archive-keyring

Import an official Nginx signing key:

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

Verify that the downloaded file contains the proper key:

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

Now set up the apt repository for stable Nginx packages:

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

If you would like to use mainline Nginx packages (Optional):

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

Now to install Nginx, run the following commands:

# apt update
# apt install nginx -y

 3. Managing the Nginx

let’s review some basic management commands.

Verify Nginx installed version:

# nginx -v

Start the Nginx web server:

# systemctl start nginx.service

Check status of the Nginx server:

# systemctl status nginx.service

Stop Nginx web server:

# systemctl stop nginx.service

Restart the Nginx web server:

# systemctl restart nginx.service

If you want to make configuration changes, Nginx can often reload without dropping connections.

# systemctl reload nginx.service

By default, Nginx service disabled to start automatically when the server boots. If you want to enable it at startup, run:

# systemctl enable nginx.service

Re-disable the service to start up at boot:

# systemctl disable nginx.service

To test syntax errors in any of Nginx files:

# nginx -t

Uninstall Nginx web server

To completely remove Nginx web server from a system, you must remove the Nginx applications, the configuration files, and any directories containing data and logs.

Warning

This process will completely remove Nginx web server, its configuration, and all website data. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.

Stop the Nginx service

# systemctl stop nginx.service

Remove any Nginx packages that previously installed.

For RHEL / CentOS/ Oracle Linux / Rocky Linux / Amazon Linux

# yum erase $(rpm -qa | grep nginx)

For Ubuntu / Debian

# apt autoremove --purge nginx

Remove Nginx data and log files.

# rm -rf /etc/nginx
# rm -rf /var/log/nginx
# rm -rf /var/www
# rm -rf /usr/share/nginx

Conclusion

Congratulations! We’ve installed latest Nginx web server on Linux system. We hope this 2 minutes stuff helped you and thank you for visiting our website.
Cheers!!!