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.
🚀 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 -ybashStep 2: Install NGINX#
$ 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 --reloadbashStep 4: Verify NGINX is Running#
Visit:
http://<your-server-ip>plaintextYou should see the NGINX welcome page.
Step 5: Hosting Your First Web Page#
Default NGINX web root:
/usr/share/nginx/htmlplaintextEdit:
sudo nano /usr/share/nginx/html/index.htmlbashExample:
<h1>Hello from NGINX on CentOS!</h1>htmlStep 6: Basic Custom NGINX Configuration#
Create:
sudo nano /etc/nginx/conf.d/mywebsite.confbashAdd:
server {
listen 80;
server_name example.com;
root /var/www/mywebsite;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}nginxReload:
sudo nginx -t
sudo systemctl reload nginxbash🎉 Done!
You’ve successfully installed and configured NGINX on CentOS.