// ssd vps

How to Install and Configure Nginx on a Linux VPS: Complete Guide

August 05, 2026 · by CLIQHOST

How to Install and Configure Nginx on a Linux VPS: Complete Guide

Nginx is one of the world's most widely used web servers, valued for its speed, low memory footprint, and ability to handle thousands of simultaneous connections. If you're running a SSD VPS or an NVMe VPS and want to host websites or web applications with top performance, Nginx is the right tool for the job.

In this guide, you'll learn how to install Nginx on Ubuntu/Debian and CentOS/AlmaLinux, configure a virtual host, enable HTTPS, and apply key performance optimizations.


Why Choose Nginx Over Apache?

Both Nginx and Apache are mature and battle-tested web servers. The key difference lies in their architecture:

  • Apache uses a process/thread-based model — one thread per connection.
  • Nginx uses an asynchronous, event-driven model — a single process handles thousands of connections without proportional memory growth.

On a resource-efficient VPS, this difference is immediately noticeable: Nginx uses significantly less RAM under heavy traffic and serves static files (images, CSS, JS) much faster.


1. Installing Nginx

On Ubuntu / Debian

sudo apt update
sudo apt install nginx -y

Start the service and enable it on boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Check the status:

sudo systemctl status nginx

On CentOS / AlmaLinux / Rocky Linux

sudo dnf install epel-release -y
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

Opening Firewall Ports

Using ufw (Ubuntu):

sudo ufw allow 'Nginx Full'
sudo ufw reload

Using firewalld (CentOS/AlmaLinux):

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

Open your server's IP address in a browser — you should see the Nginx welcome page.


2. Configuration File Structure

On Debian/Ubuntu systems, Nginx configuration files are located at:

Path Purpose
/etc/nginx/nginx.conf Global configuration
/etc/nginx/sites-available/ Available virtual host configs
/etc/nginx/sites-enabled/ Active configs (symlinks)
/var/www/html/ Default web root
/var/log/nginx/ Access and error logs

On CentOS/AlmaLinux, virtual host files are typically placed in /etc/nginx/conf.d/.


3. Setting Up a Virtual Host (Server Block)

A server block in Nginx is the equivalent of an Apache virtual host — it lets you host multiple domains on the same server.

Create a configuration file for your domain:

sudo nano /etc/nginx/sites-available/example.com

Minimal working configuration:

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    root /var/www/example.com;
    index index.html index.php;

    access_log /var/log/nginx/example.com_access.log;
    error_log  /var/log/nginx/example.com_error.log;

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

Create the web root and activate the configuration:

sudo mkdir -p /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t          # test syntax
sudo systemctl reload nginx

Tip: Always run nginx -t before reloading the service. A syntax error can bring down your entire web server.


4. Enabling HTTPS with Let's Encrypt

An SSL certificate is essential today — for both security and SEO. On a Linux VPS, you can get a free certificate using Certbot.

Install Certbot (Ubuntu/Debian)

sudo apt install certbot python3-certbot-nginx -y

Obtain and Install the Certificate

sudo certbot --nginx -d example.com -d www.example.com

Certbot will automatically update your Nginx config to include:
- HTTP → HTTPS redirect
- SSL certificate and private key
- TLS security parameters

Automatic Renewal

Certbot sets up a systemd timer or cron job automatically. Test renewal with:

sudo certbot renew --dry-run

If you need a commercial certificate with extended validation or warranty, check out SSL certificates from CLIQHOST — available in DV, OV, and Wildcard options.


5. Configuring Nginx for PHP (PHP-FPM)

If you're running WordPress or any other PHP application, you'll need PHP-FPM. Here's how to integrate Nginx with PHP 8.2:

sudo apt install php8.2-fpm php8.2-mysql php8.2-xml php8.2-curl -y

Add the following inside the server block of your virtual host config:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}

Restart both services:

sudo systemctl restart php8.2-fpm
sudo systemctl reload nginx

6. Key Performance Optimizations

One of the biggest advantages of an NVMe VPS is that you can squeeze out maximum performance through proper Nginx tuning. Here are the most important settings in /etc/nginx/nginx.conf:

Worker Processes and Connections

worker_processes auto;          # equals number of vCPUs
events {
    worker_connections 1024;    # connections per worker
    use epoll;                  # optimal for Linux
    multi_accept on;
}

Gzip Compression

http {
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml;
    gzip_min_length 256;
    gzip_comp_level 5;
}

Static File Caching

location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
    expires 30d;
    add_header Cache-Control "public, no-transform";
}

Security Limits (Basic DoS Protection)

client_max_body_size 20M;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;

7. Logs and Troubleshooting

Nginx writes two types of logs:

  • Access log — every incoming HTTP request
  • Error log — errors and warnings

Quick command to monitor errors in real time:

sudo tail -f /var/log/nginx/error.log

For professional server administration, CLIQHOST's server management service includes proactive monitoring and rapid incident response.


8. Pre-Launch Checklist

Before putting your site into production, go through this list:

  • [ ] nginx -t returns no errors
  • [ ] HTTPS is working and HTTP redirects correctly
  • [ ] PHP-FPM is running and processing .php files
  • [ ] Gzip is active (curl -I -H "Accept-Encoding: gzip" https://example.com)
  • [ ] Static file caching is enabled
  • [ ] Logs are configured per virtual host
  • [ ] Ports 80 and 443 are open in the firewall

Conclusion

Nginx is an excellent choice for any project running on a Linux VPS — from a simple blog to a high-traffic web application. The initial setup takes under an hour, and the performance and stability gains are immediate.

For a solid foundation, choose a high-performance SSD VPS from CLIQHOST or, for more demanding workloads, an NVMe VPS with ultra-low latency. Need help with the setup? Reach out to our team — we're always happy to assist.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău