Installing NGINX on Redhat/CentOS
Nginx can be installed in two ways:
We can install Nginx from default RHEL or CentOS repository. This is the easiest and quickest way, but generally, the provided packages are outdated.
We can also install Nginx from the official repo at nginx.org. For this, we have to set up the yum repository for the first time only, but after that, the provided package is always up to date.
Installing Nginx from OS repository
Step 1: Install the EPEL repository for Nginx package:
Here, EPEL stands for Extra Packages for Enterprise Linux. Since, yum as a package manager does not include the latest version of Nginx in its default repository; installing EPEL will make sure that Nginx on RHEL or CentOS stays up to date.
Use the following command to install the Epel repository.
$ sudo yum install epel-release
Step 2: Update Repository
Use the following command to update the repository.
$ sudo yum update
Step 3: Install Nginx
To install the Nginx, use the following command:
$ yum install nginx
Step 4: Verify the installation
To verify that the nginx is installed successfully or not or to know the version of nginx, use the following command:
$ sudo nginx ?v
Installing Nginx from the Official Nginx Repository
Step1: Create the yum repository for RHEL or CentOS by creating the file nginx.org in etc/yum.repos.d. To set up the yum repository, here I am using vi editor:
$ sudo vi /etc/yum.repos.d/nginx.repo
Step 2: Add the following lines of code to nginx.repo
[nginx]
name=nginx repo
baseurl= <OS>/<OSRELEASE>/$basearch/
gpgcheck=0
enabled=1
Here,
The /mainline points to the latest mainline version of NGINX open-source, delete it to get the latest stable version.
this is the name of OS, i.e. either rhel or centos
this element is the release number such as 6, 6._x, 7, 7._x_ and so on.
For example, to get the latest mainline package for CentOS 7, use the following lines:
[nginx]
name=nginx repo
baseurl=https : // nginx . org /packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
Step 3: Save the file by pressing ESC and wq at the: prompt.
Step 4: Update Repository
Use the following command to update the repository.
$ sudo yum update
Step 5: Install Nginx
To install the Nginx, use the following command:
$ yum install nginx
Step 6: Verify the installation
To verify that the nginx is installed successfully or not or to know the version of nginx, use the following command:
$ sudo nginx ?v