How To Install Nginx on CentOS 7

Published: February 3, 2018 (Updated: Feb 3, 2018)

Enjoying this content? Subscribe to the Channel!

Lightning Fast: How to Install the Nginx Web Server on CentOS 7

Welcome back to Darren’s Tech Tutorials!

If you’re looking to deploy a high-performance, lightweight, and modern web server, Nginx (pronounced “Engine-X”) is almost certainly at the top of your list. It’s renowned for its speed, scalability, and efficiency, making it the perfect choice for serving dynamic and static content.

In this comprehensive guide, we’re going to walk through the simple, reliable process of getting Nginx up and running quickly on your CentOS 7 server. We’ve broken down the installation into four easy steps. Let’s dive in!


Step 1: Add the EPEL Repository

By default, Nginx is not included in the standard CentOS 7 software repositories. To easily install it using the yum package manager, we first need to enable the EPEL (Extra Packages for Enterprise Linux) repository.

Run the following command to add the repository:

sudo yum install epel-release

You will be prompted to confirm the installation. Once complete, your system is ready to find and download the Nginx package.

Step 2: Install the Nginx Web Server

With the EPEL repository enabled, installing Nginx is straightforward. We simply instruct yum to pull the package down:

sudo yum install nginx

Confirm the installation when prompted. Once the installation process finishes, the Nginx files will be placed on your server, but the service won’t be running yet.

Step 3: Start and Enable the Nginx Service

After the installation is complete, we need to perform two critical actions using systemctl:

3a. Start the Service Immediately

To get Nginx running right now, use the start command:

sudo systemctl start nginx

3b. Enable Nginx on Boot

If your server reboots, you definitely want Nginx to start up automatically without manual intervention. We enable the service to ensure this happens:

sudo systemctl enable nginx

You should see a message confirming that a symlink was created, which means Nginx is now properly configured to survive a server restart.

Step 4: Verify the Installation and Configure the Firewall

The Nginx service is running, but we need to check two things: the service status and the server’s firewall configuration.

4a. Check Service Status

Run this command to confirm that Nginx is active and running:

sudo systemctl status nginx

You should see an output that shows Active: active (running).

4b. Configure the Firewall (Crucial Step!)

Even if the service is running, the CentOS firewall might be blocking incoming web traffic on ports 80 (HTTP) or 443 (HTTPS). We need to open the HTTP service permanently:

First, add the HTTP service:

sudo firewall-cmd --permanent --add-service=http

Next, reload the firewall configuration to apply the change immediately:

sudo firewall-cmd --reload

The firewall is now configured to allow outside connections to your new web server.

4c. Test Nginx in Your Browser

Finally, it’s time to see your hard work pay off! Open your favorite web browser and navigate to your server’s IP address or domain name.

For example, if your server’s IP is 192.168.1.10, navigate to:

http://192.168.1.10

If everything worked correctly, you should see the default Nginx welcoming page!


You’re All Set!

Congratulations! You have successfully installed the powerful Nginx web server on your CentOS 7 machine. You are now ready to host your websites, set up reverse proxies, or start serving high-performance web content.

Ready for more detail? A full text tutorial including all commands needed can be found on our companion website right here.

If this tutorial helped you get Nginx running smoothly, please consider hitting the like button on the video and subscribing to Darren’s Tech Tutorials for more clear, actionable guides! Drop a comment below if you run into any issues—we love helping you conquer your tech challenges!