How to Install NGINX on Your Server

How to Install NGINX on Your Server: A Complete Step-by-Step Guide
When it comes to building a fast, scalable, and efficient web infrastructure, NGINX is a top choice among developers and system administrators. Known for its lightweight architecture and high concurrency support, NGINX can serve thousands of connections with minimal resources.
In this tutorial, we’ll guide you through installing and configuring NGINX on a Linux-based server (such as Ubuntu or CentOS), whether you’re using a VPS from Vicservers or a cloud server. We’ll also cover the basics of how NGINX works, how to serve your first web page, and how to secure it with SSL.
What is NGINX?
NGINX (pronounced “Engine-X”) is an open-source web server that can also be used as a reverse proxy, load balancer, and HTTP cache. It was originally created to handle the C10k problem—serving 10,000 simultaneous client connections on one server—and it does that extremely well.
Why choose NGINX?
- High performance under load
- Low memory consumption
- Built-in reverse proxy and load balancing
- Excellent with static content
- Perfect for modern web apps and APIs
Prerequisites
Before we begin, make sure you have:
✅ A server running Ubuntu 20.04+, Debian, or CentOS
✅ A user account with sudo privileges
✅ A stable internet connection
✅ SSH access to your server
If you’re using Vicservers, your server is ready to go with root access and full control.
1. Connect to Your Server
Open a terminal and connect via SSH:
ssh youruser@your_server_ip
Replace youruser
and your_server_ip
with your actual SSH user and IP address.
2. Update Your System
It’s always a good practice to update your system before installing any new software:
For Ubuntu/Debian:
sudo apt update && sudo apt upgrade -y
For CentOS/RHEL:
sudo yum update -y
3. Installing NGINX
On Ubuntu/Debian
NGINX is available via the default package repositories.
sudo apt install nginx -y
On CentOS/RHEL
Install the EPEL repository first:
sudo yum install epel-release -y
sudo yum install nginx -y
Start and enable NGINX:
sudo systemctl start nginx
sudo systemctl enable nginx
4. Verify NGINX is Running
Check the status:
sudo systemctl status nginx
You should see active (running)
.
You can also verify by entering your server’s IP in a browser:
http://your_server_ip
You’ll see the default NGINX welcome page—you’re live!
5. Configure the Firewall
If UFW is running (Ubuntu), allow HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
sudo ufw reload
For firewalld (CentOS):
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
6. Understanding NGINX File Structure
NGINX configuration lives in /etc/nginx/
. Here’s what matters:
/etc/nginx/nginx.conf
: Main config file/etc/nginx/sites-available/
: Available site configurations (Ubuntu)/etc/nginx/sites-enabled/
: Symlinks to enabled sites/var/www/html/
: Default web root directory/etc/nginx/conf.d/
: Custom configs (CentOS)
Let’s host a simple site next.
7. Hosting a Basic HTML Website with NGINX
Step 1: Create Your Web Directory
sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
Step 2: Add an HTML File
nano /var/www/example.com/html/index.html
Paste:
<!DOCTYPE html>
<html>
<head><title>Welcome to Example.com</title></head>
<body><h1>Success! NGINX is serving your website.</h1></body>
</html>
Step 3: Create a Server Block (Ubuntu)
sudo nano /etc/nginx/sites-available/example.com
Paste:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable the site and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
If you’re using CentOS, place your config in /etc/nginx/conf.d/example.com.conf
.
8. Testing DNS and Hosts File (Optional)
If your domain hasn’t propagated yet, map it locally for testing:
sudo nano /etc/hosts
Add:
your_server_ip example.com www.example.com
Then visit http://example.com
in your browser—you should see your test page.
9. Setting Up SSL with Let’s Encrypt (HTTPS)
Let’s Encrypt provides free SSL certificates. Use Certbot to install and manage them.
Step 1: Install Certbot
Ubuntu:
sudo apt install certbot python3-certbot-nginx -y
CentOS:
sudo yum install certbot python3-certbot-nginx -y
Step 2: Obtain a Certificate
sudo certbot --nginx
Follow the prompts to select your domain and enable redirect from HTTP to HTTPS.
Step 3: Test Renewal
sudo certbot renew --dry-run
Your site is now secured with HTTPS!
10. Tweaking Performance
For high-traffic sites, tweak these in /etc/nginx/nginx.conf
:
worker_processes auto;
worker_connections 1024;
keepalive_timeout 65;
gzip on;
Use sudo nginx -t
to test and sudo systemctl reload nginx
to apply.
11. Logging and Debugging
- Access logs:
/var/log/nginx/access.log
- Error logs:
/var/log/nginx/error.log
To tail logs:
sudo tail -f /var/log/nginx/access.log
Check your server block if your site isn’t displaying.
12. Uninstalling NGINX (If Needed)
Ubuntu:
sudo apt remove nginx nginx-common -y
CentOS:
sudo yum remove nginx -y
Final Thoughts
Installing NGINX on your server is one of the most important steps toward building a scalable, secure, and high-performance web infrastructure. Whether you’re running a simple portfolio or a complex application backend, NGINX gives you the flexibility and speed that modern websites demand.
Why Choose Vicservers for NGINX Hosting?
Vicservers provides VPS and cloud hosting optimized for NGINX-based stacks. With fast SSD storage, root access, easy OS selection (Ubuntu, Debian, CentOS), and 24/7 support, we help developers and businesses deploy confidently.
Benefits:
- Pre-configured NGINX VPS options
- Free SSL with Let’s Encrypt
- One-click snapshots and backups
- Expert Linux support
- Affordable plans for every need
Get Started Today
Launch your NGINX VPS at Vicservers.com
Need help? Our support team is just a click away.
Want more guides? Browse our blog for tutorials, tips, and best practices.
Vicservers — Empowering developers and businesses with dependable hosting infrastructure.
By Vicservers — Powering Your Web Presence with Reliable Hosting Solutions