All posts

Blog

How to Install and Configure NGINX Server on CentOS

A simple and clear step-by-step tutorial on installing NGINX on CentOS, configuring your first website, enabling firewall rules, and verifying everything works.

Dec 8, 2025 1 min
How to Install and Configure NGINX Server on CentOS

🚀 How to Install and Configure NGINX on CentOS#

NGINX is one of the most popular web servers in the world. It’s fast, lightweight, and easy to configure — perfect for hosting websites, APIs, or static content.

In this guide, you’ll learn how to install NGINX on CentOS, start the service, configure a basic website, and verify the installation.

Client

HTTP request

Firewall

port 80/443

NGINX

reverse proxy

Web root

/usr/share/nginx/html

Step 1: Update Your System#

sudo yum update -y
bash

Step 2: Install NGINX#

root@centos: ~

$ sudo yum install nginx -y

Installed: nginx.x86_64 1:1.20.1-14.el9 Complete!

$ sudo systemctl start nginx

$ sudo systemctl enable nginx

$ sudo systemctl status nginx

● nginx.service - The nginx HTTP and reverse proxy server Active: active (running)

Step 3: Allow NGINX in the Firewall#

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
bash

Step 4: Verify NGINX is Running#

Visit:

http://<your-server-ip>
plaintext

You should see the NGINX welcome page.

Step 5: Hosting Your First Web Page#

Default NGINX web root:

/usr/share/nginx/html
plaintext

Edit:

sudo nano /usr/share/nginx/html/index.html
bash

Example:

<h1>Hello from NGINX on CentOS!</h1>
html

Step 6: Basic Custom NGINX Configuration#

Create:

sudo nano /etc/nginx/conf.d/mywebsite.conf
bash

Add:

server {
    listen 80;
    server_name example.com;
    root /var/www/mywebsite;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
nginx

Reload:

sudo nginx -t
sudo systemctl reload nginx
bash

🎉 Done!

You’ve successfully installed and configured NGINX on CentOS.

Loading comments...
Search posts & projects