Krishan Chawla

Back

How to Install and Configure NGINX Server on CentOSBlur image

🚀 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.

Step 1: Update Your System#

sudo yum update -y
bash

Step 2: Install NGINX#

sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
bash

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.