CentOSLinuxTutorials

How To Install Nginx Using Yum Command on CentOS

Install Nginx Using Yum Command On CentOS

In this tutorial, we will show you how to Install Nginx using yum command on CentOS Linux. For those of you who didn’t know, 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 is more resource-friendly than Apache in most cases and can be used as a web server or a reverse proxy.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. So today I’m going to show you how to set up an Nginx web server on CentOS systems. It’s really not that difficult. Let’s start with Nginx.

Prerequisites

  • A server running one of the following operating systems: CentOS Linux.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nginx Using Yum Command on CentOS

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo yum clean all
sudo yum update

Step 2 Installing Nginx on CentOS.

Before we can install Nginx, we need to add the Nginx repository to our system. This will ensure that we receive the latest version of Nginx and its dependencies. To add the Nginx repository, we will use the following command:

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

Add the following contents to the file:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

After the Nginx repository has been added to our system, we can install Nginx by running the following command:

sudo yum update
sudo yum install nginx

Once the installation is complete, we can start Nginx by running the following command:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 3. Configuration files/folders.

  • The main configuration file for Nginx is /etc/nginx/nginx.conf
  • Virtual hosts are defined in /etc/nginx/sites-available/default

Step 4. Configure Firewall.

If your server is protected by a firewall you need to open both HTTP (80) and HTTPS (443) ports:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Step 5. Test Nginx.

Navigating to your Server’s IP address (assuming you have no other server listening on port 80), you will be greeted with the standard welcome page:

Install Nginx Using Yum Command On CentOS

Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx web server in the CentOS system. For additional help or useful information, we recommend you check the official Nginx website.

Squid Install Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “Nginx Webserver” installation, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button